remove unnecessary trait bounds

This commit is contained in:
Jorge Aparicio 2017-04-14 00:33:07 -05:00
parent bf17ee7422
commit c6bf89a318
3 changed files with 15 additions and 28 deletions

View file

@ -40,7 +40,7 @@ fn main() {
); );
// Ceilings // Ceilings
for i in 1..(1 << bits) + 1 { for i in 0..(1 << bits) + 1 {
let c = Ident::new(format!("C{}", i)); let c = Ident::new(format!("C{}", i));
let u = Ident::new(format!("U{}", i)); let u = Ident::new(format!("U{}", i));

View file

@ -1,3 +1,6 @@
//! Stack Resource Policy
#![deny(missing_docs)]
#![deny(warnings)] #![deny(warnings)]
#![feature(asm)] #![feature(asm)]
#![feature(const_fn)] #![feature(const_fn)]
@ -52,10 +55,7 @@ impl<T, C> Resource<T, C> {
} }
} }
impl<T, CEILING> Resource<T, C<CEILING>> impl<T, CEILING> Resource<T, C<CEILING>> {
where
C<CEILING>: Ceiling,
{
/// Borrows the resource for the duration of another resource's critical /// Borrows the resource for the duration of another resource's critical
/// section /// section
/// ///
@ -68,7 +68,6 @@ where
where where
SCEILING: GreaterThanOrEqual<CEILING>, SCEILING: GreaterThanOrEqual<CEILING>,
CEILING: GreaterThanOrEqual<PRIORITY>, CEILING: GreaterThanOrEqual<PRIORITY>,
P<PRIORITY>: Priority,
{ {
unsafe { &*self.data.get() } unsafe { &*self.data.get() }
} }
@ -82,7 +81,6 @@ where
) -> &'task T ) -> &'task T
where where
CEILING: Cmp<PRIORITY, Output = Equal>, CEILING: Cmp<PRIORITY, Output = Equal>,
P<PRIORITY>: Priority,
{ {
unsafe { &*self.data.get() } unsafe { &*self.data.get() }
} }
@ -95,7 +93,6 @@ where
) -> &'task mut T ) -> &'task mut T
where where
CEILING: Cmp<PRIORITY, Output = Equal>, CEILING: Cmp<PRIORITY, Output = Equal>,
P<PRIORITY>: Priority,
{ {
unsafe { &mut *self.data.get() } unsafe { &mut *self.data.get() }
} }
@ -117,10 +114,8 @@ where
) -> R ) -> R
where where
F: FnOnce(&T, C<CEILING>) -> R, F: FnOnce(&T, C<CEILING>) -> R,
C<CEILING>: Ceiling,
CEILING: Cmp<PRIORITY, Output = Greater> + Cmp<UMAX, Output = Less> CEILING: Cmp<PRIORITY, Output = Greater> + Cmp<UMAX, Output = Less>
+ Level, + Level,
P<PRIORITY>: Priority,
{ {
unsafe { unsafe {
let old_basepri = basepri::read(); let old_basepri = basepri::read();
@ -147,10 +142,8 @@ where
) -> R ) -> R
where where
F: FnOnce(&mut T) -> R, F: FnOnce(&mut T) -> R,
C<CEILING>: Ceiling,
CEILING: Cmp<PRIORITY, Output = Greater> + Cmp<UMAX, Output = Less> CEILING: Cmp<PRIORITY, Output = Greater> + Cmp<UMAX, Output = Less>
+ Level, + Level,
P<PRIORITY>: Priority,
{ {
unsafe { unsafe {
let old_basepri = basepri::read(); let old_basepri = basepri::read();
@ -164,9 +157,9 @@ where
} }
} }
unsafe impl<T, CEILING> Sync for Resource<T, CEILING> unsafe impl<T, C> Sync for Resource<T, C>
where where
CEILING: Ceiling, C: Ceiling,
{ {
} }
@ -197,10 +190,7 @@ where
} }
} }
impl<Periph, CEILING> Peripheral<Periph, C<CEILING>> impl<Periph, CEILING> Peripheral<Periph, C<CEILING>> {
where
C<CEILING>: Ceiling,
{
/// See [Resource.borrow](./struct.Resource.html#method.borrow) /// See [Resource.borrow](./struct.Resource.html#method.borrow)
pub fn borrow<'cs, PRIORITY, SCEILING>( pub fn borrow<'cs, PRIORITY, SCEILING>(
&'static self, &'static self,
@ -221,7 +211,6 @@ where
) -> &'task Periph ) -> &'task Periph
where where
CEILING: Cmp<PRIORITY, Output = Equal>, CEILING: Cmp<PRIORITY, Output = Equal>,
P<PRIORITY>: Priority,
{ {
unsafe { &*self.peripheral.get() } unsafe { &*self.peripheral.get() }
} }
@ -235,10 +224,8 @@ where
) -> R ) -> R
where where
F: FnOnce(&Periph, C<CEILING>) -> R, F: FnOnce(&Periph, C<CEILING>) -> R,
C<CEILING>: Ceiling,
CEILING: Cmp<PRIORITY, Output = Greater> + Cmp<UMAX, Output = Less> CEILING: Cmp<PRIORITY, Output = Greater> + Cmp<UMAX, Output = Less>
+ Level, + Level,
P<PRIORITY>: Priority,
{ {
unsafe { unsafe {
let old_basepri = basepri::read(); let old_basepri = basepri::read();
@ -279,7 +266,7 @@ where
r r
} }
/// Requests the execution of the task `task` /// Requests the execution of a `task`
pub fn request<T, P>(_task: fn(T, P)) pub fn request<T, P>(_task: fn(T, P))
where where
T: Context + Nr, T: Context + Nr,
@ -320,12 +307,13 @@ impl<T> P<T>
where where
T: Level, T: Level,
{ {
#[doc(hidden)]
pub fn hw() -> u8 { pub fn hw() -> u8 {
T::hw() T::hw()
} }
} }
/// A valid ceiling /// A valid resource ceiling
/// ///
/// DO NOT IMPLEMENT THIS TRAIT YOURSELF /// DO NOT IMPLEMENT THIS TRAIT YOURSELF
pub unsafe trait Ceiling {} pub unsafe trait Ceiling {}
@ -339,10 +327,11 @@ pub unsafe trait GreaterThanOrEqual<RHS> {}
/// ///
/// DO NOT IMPLEMENT THIS TRAIT YOURSELF /// DO NOT IMPLEMENT THIS TRAIT YOURSELF
pub unsafe trait Level { pub unsafe trait Level {
/// Interrupt hardware level
fn hw() -> u8; fn hw() -> u8;
} }
/// A valid priority level /// A valid task priority
/// ///
/// DO NOT IMPLEMENT THIS TRAIT YOURSELF /// DO NOT IMPLEMENT THIS TRAIT YOURSELF
pub unsafe trait Priority {} pub unsafe trait Priority {}
@ -354,8 +343,6 @@ fn logical2hw(logical: u8) -> u8 {
/// Priority 0, the lowest priority /// Priority 0, the lowest priority
pub type P0 = P<::typenum::U0>; pub type P0 = P<::typenum::U0>;
unsafe impl Priority for P0 {}
/// Declares tasks /// Declares tasks
#[macro_export] #[macro_export]
macro_rules! tasks { macro_rules! tasks {

View file

@ -14,8 +14,8 @@ tasks!(device, {
j1: (Exti0, P1), j1: (Exti0, P1),
}); });
// WRONG. `init` must have signature `fn(C16)` // WRONG. `init` must have signature `fn(P0, C16)`
fn init(_: C1) {} fn init(_: P0, _: C1) {}
fn idle(_: P0) {} fn idle(_: P0) {}