File tree Expand file tree Collapse file tree 8 files changed +49
-15
lines changed
Expand file tree Collapse file tree 8 files changed +49
-15
lines changed Original file line number Diff line number Diff line change 1+ name : Clippy
2+
3+ on :
4+ push :
5+ branches : [ staging, trying, master ]
6+ pull_request :
7+ branches : [ master ]
8+
9+ defaults :
10+ run :
11+ shell : bash
12+
13+ env :
14+ CLIPPY_PARAMS : -W clippy::all -W clippy::pedantic -W clippy::nursery -W clippy::cargo
15+
16+ jobs :
17+ clippy :
18+ name : Clippy
19+ runs-on : ubuntu-latest
20+ strategy :
21+ matrix :
22+ cargo_flags :
23+ - " --no-default-features"
24+ - " --all-features"
25+ steps :
26+ - name : Checkout source code
27+ uses : actions/checkout@v3
28+
29+ - name : Install Rust toolchain
30+ uses : dtolnay/rust-toolchain@stable
31+ with :
32+ toolchain : stable
33+ components : clippy
34+
35+ - name : Run clippy
36+ run : cargo clippy --all ${{ matrix.cargo_flags }} -- -D warnings
Original file line number Diff line number Diff line change 2626//! a target-specific implementation instead, typically provided by a HAL or RTOS crate.
2727
2828#![ no_std]
29+ #![ allow( clippy:: missing_safety_doc) ]
2930
3031pub mod asm;
3132pub mod delay;
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ impl Mcounteren {
3030 /// Supervisor "hpm\[x\]" Enable (bits 3-31)
3131 #[ inline]
3232 pub fn hpm ( & self , index : usize ) -> bool {
33- assert ! ( 3 <= index && index < 32 ) ;
33+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
3434 self . bits . get_bit ( index)
3535 }
3636}
@@ -54,12 +54,12 @@ set_clear_csr!(
5454
5555#[ inline]
5656pub unsafe fn set_hpm ( index : usize ) {
57- assert ! ( 3 <= index && index < 32 ) ;
57+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
5858 _set ( 1 << index) ;
5959}
6060
6161#[ inline]
6262pub unsafe fn clear_hpm ( index : usize ) {
63- assert ! ( 3 <= index && index < 32 ) ;
63+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
6464 _clear ( 1 << index) ;
6565}
Original file line number Diff line number Diff line change 88// which would be the best way we implement this using Rust?
99
1010use bit_field:: BitField ;
11- use core:: mem:: size_of;
1211
1312/// mstatus register
1413#[ derive( Clone , Copy , Debug ) ]
@@ -205,7 +204,7 @@ impl Mstatus {
205204 /// signals the presence of some dirty state
206205 #[ inline]
207206 pub fn sd ( & self ) -> bool {
208- self . bits . get_bit ( size_of :: < usize > ( ) * 8 - 1 )
207+ self . bits . get_bit ( usize :: BITS as usize - 1 )
209208 }
210209}
211210
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ impl Pmpcsr {
7272 3 => Range :: NAPOT ,
7373 _ => unreachable ! ( ) ,
7474 } ,
75- locked : byte. get_bit ( 7 ) as bool ,
75+ locked : byte. get_bit ( 7 ) ,
7676 }
7777 }
7878}
Original file line number Diff line number Diff line change 11//! scause register
22
33use bit_field:: BitField ;
4- use core:: mem:: size_of;
54
65/// scause register
76#[ derive( Clone , Copy ) ]
@@ -90,7 +89,7 @@ impl Scause {
9089 /// Returns the code field
9190 #[ inline]
9291 pub fn code ( & self ) -> usize {
93- let bit = 1 << ( size_of :: < usize > ( ) * 8 - 1 ) ;
92+ let bit = 1 << ( usize :: BITS as usize - 1 ) ;
9493 self . bits & !bit
9594 }
9695
@@ -107,7 +106,7 @@ impl Scause {
107106 /// Is trap cause an interrupt.
108107 #[ inline]
109108 pub fn is_interrupt ( & self ) -> bool {
110- self . bits . get_bit ( size_of :: < usize > ( ) * 8 - 1 )
109+ self . bits . get_bit ( usize :: BITS as usize - 1 )
111110 }
112111
113112 /// Is trap cause an exception.
@@ -139,7 +138,7 @@ pub unsafe fn set(cause: Trap) {
139138 Interrupt :: UserExternal => 8 ,
140139 Interrupt :: SupervisorExternal => 9 ,
141140 Interrupt :: Unknown => panic ! ( "unknown interrupt" ) ,
142- } | ( 1 << ( size_of :: < usize > ( ) * 8 - 1 ) ) )
141+ } | ( 1 << ( usize :: BITS as usize - 1 ) ) )
143142 } // interrupt bit is 1
144143 Trap :: Exception ( e) => match e {
145144 Exception :: InstructionMisaligned => 0 ,
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ impl Scounteren {
3030 /// User "hpm\[x\]" Enable (bits 3-31)
3131 #[ inline]
3232 pub fn hpm ( & self , index : usize ) -> bool {
33- assert ! ( 3 <= index && index < 32 ) ;
33+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
3434 self . bits . get_bit ( index)
3535 }
3636}
@@ -54,12 +54,12 @@ set_clear_csr!(
5454
5555#[ inline]
5656pub unsafe fn set_hpm ( index : usize ) {
57- assert ! ( 3 <= index && index < 32 ) ;
57+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
5858 _set ( 1 << index) ;
5959}
6060
6161#[ inline]
6262pub unsafe fn clear_hpm ( index : usize ) {
63- assert ! ( 3 <= index && index < 32 ) ;
63+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
6464 _clear ( 1 << index) ;
6565}
Original file line number Diff line number Diff line change 22
33pub use super :: mstatus:: FS ;
44use bit_field:: BitField ;
5- use core:: mem:: size_of;
65
76/// Supervisor Status Register
87#[ derive( Clone , Copy , Debug ) ]
@@ -92,7 +91,7 @@ impl Sstatus {
9291 /// signals the presence of some dirty state
9392 #[ inline]
9493 pub fn sd ( & self ) -> bool {
95- self . bits . get_bit ( size_of :: < usize > ( ) * 8 - 1 )
94+ self . bits . get_bit ( usize :: BITS as usize - 1 )
9695 }
9796}
9897
You can’t perform that action at this time.
0 commit comments