Skip to content

Commit a3289cb

Browse files
committed
Make Clippy happy.
1 parent 718cd17 commit a3289cb

File tree

11 files changed

+53
-49
lines changed

11 files changed

+53
-49
lines changed

src/itm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ impl<'p> fmt::Write for Port<'p> {
2828
}
2929

3030
/// Writes a `buffer` to the ITM `port`
31+
#[allow(clippy::cast_ptr_alignment)]
32+
#[allow(clippy::transmute_ptr_to_ptr)]
3133
pub fn write_all(port: &mut Stim, buffer: &[u8]) {
3234
unsafe {
3335
let mut len = buffer.len();
@@ -86,6 +88,8 @@ pub fn write_all(port: &mut Stim, buffer: &[u8]) {
8688
/// // Or equivalently
8789
/// itm::write_aligned(&itm.stim[0], &Aligned(*b"Hello, world!\n"));
8890
/// ```
91+
#[allow(clippy::cast_ptr_alignment)]
92+
#[allow(clippy::transmute_ptr_to_ptr)]
8993
pub fn write_aligned(port: &mut Stim, buffer: &Aligned<A4, [u8]>) {
9094
unsafe {
9195
let len = buffer.len();
@@ -102,7 +106,7 @@ pub fn write_aligned(port: &mut Stim, buffer: &Aligned<A4, [u8]>) {
102106

103107
// 3 bytes or less left
104108
let mut left = len & 0b11;
105-
let mut ptr = buffer.as_ptr().offset(split as isize);
109+
let mut ptr = buffer.as_ptr().add(split);
106110

107111
// at least 2 bytes left
108112
if left > 1 {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![cfg_attr(feature = "inline-asm", feature(asm))]
3333
#![deny(missing_docs)]
3434
#![no_std]
35+
#![allow(clippy::identity_op)]
3536

3637
extern crate aligned;
3738
extern crate bare_metal;

src/peripheral/cbp.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl CBP {
7878
// CMSIS-Core implementation and use fixed values.
7979
unsafe {
8080
self.dcisw.write(
81-
(((way as u32) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS)
82-
| (((set as u32) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS),
81+
((u32::from(way) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS)
82+
| ((u32::from(set) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS),
8383
);
8484
}
8585
}
@@ -108,8 +108,8 @@ impl CBP {
108108
// See comment for dcisw() about the format here
109109
unsafe {
110110
self.dccsw.write(
111-
(((way as u32) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS)
112-
| (((set as u32) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS),
111+
((u32::from(way) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS)
112+
| ((u32::from(set) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS),
113113
);
114114
}
115115
}
@@ -130,8 +130,8 @@ impl CBP {
130130
// See comment for dcisw() about the format here
131131
unsafe {
132132
self.dccisw.write(
133-
(((way as u32) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS)
134-
| (((set as u32) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS),
133+
((u32::from(way) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS)
134+
| ((u32::from(set) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS),
135135
);
136136
}
137137
}

src/peripheral/cpuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl CPUID {
9090

9191
unsafe {
9292
self.csselr.write(
93-
(((level as u32) << CSSELR_LEVEL_POS) & CSSELR_LEVEL_MASK)
93+
((u32::from(level) << CSSELR_LEVEL_POS) & CSSELR_LEVEL_MASK)
9494
| (((ind as u32) << CSSELR_IND_POS) & CSSELR_IND_MASK),
9595
)
9696
}

src/peripheral/nvic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl NVIC {
9090
let nr = interrupt.nr();
9191

9292
unsafe {
93-
self.stir.write(nr as u32);
93+
self.stir.write(u32::from(nr));
9494
}
9595
}
9696

src/peripheral/scb.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ impl Exception {
230230
/// Returns the IRQ number of this `Exception`
231231
///
232232
/// The return value is always within the closed range `[-1, -14]`
233-
pub fn irqn(&self) -> i8 {
234-
match *self {
233+
pub fn irqn(self) -> i8 {
234+
match self {
235235
Exception::NonMaskableInt => -14,
236236
Exception::HardFault => -13,
237237
#[cfg(not(armv6m))]
@@ -709,7 +709,6 @@ impl SCB {
709709
}
710710

711711
/// System handlers, exceptions with configurable priority
712-
#[allow(non_camel_case_types)]
713712
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
714713
pub enum SystemHandler {
715714
// NonMaskableInt, // priority is fixed
@@ -745,8 +744,8 @@ pub enum SystemHandler {
745744
}
746745

747746
impl SystemHandler {
748-
fn index(&self) -> u8 {
749-
match *self {
747+
fn index(self) -> u8 {
748+
match self {
750749
#[cfg(not(armv6m))]
751750
SystemHandler::MemoryManagement => 4,
752751
#[cfg(not(armv6m))]

src/peripheral/syst.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub enum SystClkSource {
2626
External,
2727
}
2828

29-
const SYST_COUNTER_MASK: u32 = 0x00ffffff;
29+
const SYST_COUNTER_MASK: u32 = 0x00ff_ffff;
3030

3131
const SYST_CSR_ENABLE: u32 = 1 << 0;
3232
const SYST_CSR_TICKINT: u32 = 1 << 1;
@@ -81,10 +81,10 @@ impl SYST {
8181
/// bit that indicates that the timer has wrapped (cf. `SYST.has_wrapped`)
8282
pub fn get_clock_source(&mut self) -> SystClkSource {
8383
// NOTE(unsafe) atomic read with no side effects
84-
let clk_source_bit = self.csr.read() & SYST_CSR_CLKSOURCE != 0;
85-
match clk_source_bit {
86-
false => SystClkSource::External,
87-
true => SystClkSource::Core,
84+
if self.csr.read() & SYST_CSR_CLKSOURCE != 0 {
85+
SystClkSource::Core
86+
} else {
87+
SystClkSource::External
8888
}
8989
}
9090

src/register/apsr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ pub struct Apsr {
88

99
impl Apsr {
1010
/// Returns the contents of the register as raw bits
11-
pub fn bits(&self) -> u32 {
11+
pub fn bits(self) -> u32 {
1212
self.bits
1313
}
1414

1515
/// DSP overflow and saturation flag
16-
pub fn q(&self) -> bool {
16+
pub fn q(self) -> bool {
1717
self.bits & (1 << 27) == (1 << 27)
1818
}
1919

2020
/// Overflow flag
21-
pub fn v(&self) -> bool {
21+
pub fn v(self) -> bool {
2222
self.bits & (1 << 28) == (1 << 28)
2323
}
2424

2525
/// Carry or borrow flag
26-
pub fn c(&self) -> bool {
26+
pub fn c(self) -> bool {
2727
self.bits & (1 << 29) == (1 << 29)
2828
}
2929

3030
/// Zero flag
31-
pub fn z(&self) -> bool {
31+
pub fn z(self) -> bool {
3232
self.bits & (1 << 30) == (1 << 30)
3333
}
3434

3535
/// Negative flag
36-
pub fn n(&self) -> bool {
36+
pub fn n(self) -> bool {
3737
self.bits & (1 << 31) == (1 << 31)
3838
}
3939
}

src/register/control.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ impl Control {
1515

1616
/// Returns the contents of the register as raw bits
1717
#[inline]
18-
pub fn bits(&self) -> u32 {
18+
pub fn bits(self) -> u32 {
1919
self.bits
2020
}
2121

2222
/// Thread mode privilege level
2323
#[inline]
24-
pub fn npriv(&self) -> Npriv {
24+
pub fn npriv(self) -> Npriv {
2525
if self.bits & (1 << 0) == (1 << 0) {
2626
Npriv::Unprivileged
2727
} else {
@@ -41,7 +41,7 @@ impl Control {
4141

4242
/// Currently active stack pointer
4343
#[inline]
44-
pub fn spsel(&self) -> Spsel {
44+
pub fn spsel(self) -> Spsel {
4545
if self.bits & (1 << 1) == (1 << 1) {
4646
Spsel::Psp
4747
} else {
@@ -61,7 +61,7 @@ impl Control {
6161

6262
/// Whether context floating-point is currently active
6363
#[inline]
64-
pub fn fpca(&self) -> Fpca {
64+
pub fn fpca(self) -> Fpca {
6565
if self.bits & (1 << 2) == (1 << 2) {
6666
Fpca::Active
6767
} else {
@@ -92,14 +92,14 @@ pub enum Npriv {
9292
impl Npriv {
9393
/// Is in privileged thread mode?
9494
#[inline]
95-
pub fn is_privileged(&self) -> bool {
96-
*self == Npriv::Privileged
95+
pub fn is_privileged(self) -> bool {
96+
self == Npriv::Privileged
9797
}
9898

9999
/// Is in unprivileged thread mode?
100100
#[inline]
101-
pub fn is_unprivileged(&self) -> bool {
102-
*self == Npriv::Unprivileged
101+
pub fn is_unprivileged(self) -> bool {
102+
self == Npriv::Unprivileged
103103
}
104104
}
105105

@@ -115,14 +115,14 @@ pub enum Spsel {
115115
impl Spsel {
116116
/// Is MSP the current stack pointer?
117117
#[inline]
118-
pub fn is_msp(&self) -> bool {
119-
*self == Spsel::Msp
118+
pub fn is_msp(self) -> bool {
119+
self == Spsel::Msp
120120
}
121121

122122
/// Is PSP the current stack pointer?
123123
#[inline]
124-
pub fn is_psp(&self) -> bool {
125-
*self == Spsel::Psp
124+
pub fn is_psp(self) -> bool {
125+
self == Spsel::Psp
126126
}
127127
}
128128

@@ -138,14 +138,14 @@ pub enum Fpca {
138138
impl Fpca {
139139
/// Is a floating-point context active?
140140
#[inline]
141-
pub fn is_active(&self) -> bool {
142-
*self == Fpca::Active
141+
pub fn is_active(self) -> bool {
142+
self == Fpca::Active
143143
}
144144

145145
/// Is a floating-point context not active?
146146
#[inline]
147-
pub fn is_not_active(&self) -> bool {
148-
*self == Fpca::NotActive
147+
pub fn is_not_active(self) -> bool {
148+
self == Fpca::NotActive
149149
}
150150
}
151151

src/register/faultmask.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ pub enum Faultmask {
1111

1212
impl Faultmask {
1313
/// All exceptions are active
14-
pub fn is_active(&self) -> bool {
15-
*self == Faultmask::Active
14+
pub fn is_active(self) -> bool {
15+
self == Faultmask::Active
1616
}
1717

1818
/// All exceptions, except for NMI, are inactive
19-
pub fn is_inactive(&self) -> bool {
20-
*self == Faultmask::Inactive
19+
pub fn is_inactive(self) -> bool {
20+
self == Faultmask::Inactive
2121
}
2222
}
2323

src/register/primask.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ pub enum Primask {
1111

1212
impl Primask {
1313
/// All exceptions with configurable priority are active
14-
pub fn is_active(&self) -> bool {
15-
*self == Primask::Active
14+
pub fn is_active(self) -> bool {
15+
self == Primask::Active
1616
}
1717

1818
/// All exceptions with configurable priority are inactive
19-
pub fn is_inactive(&self) -> bool {
20-
*self == Primask::Inactive
19+
pub fn is_inactive(self) -> bool {
20+
self == Primask::Inactive
2121
}
2222
}
2323

0 commit comments

Comments
 (0)