Skip to content

Commit 67452b4

Browse files
bors[bot]newAM
andauthored
Merge #145
145: fix new clippy lints r=therealprof a=newAM This resolves these 6 clippy failures: ```text warning: name `HSI` contains a capitalized acronym --> src/rcc.rs:93:9 | 93 | HSI, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Hsi` | = note: `#[warn(clippy::upper_case_acronyms)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms warning: name `HSE` contains a capitalized acronym --> src/rcc.rs:95:9 | 95 | HSE(u32, super::HSEBypassMode), | ^^^ help: consider making the acronym lowercase, except the initial letter: `Hse` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> src/time.rs:47:1 | 47 | impl Into<Hertz> for KiloHertz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::from_over_into)]` on by default = help: consider to implement `From<time::KiloHertz>` instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> src/time.rs:53:1 | 53 | impl Into<Hertz> for MegaHertz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider to implement `From<time::MegaHertz>` instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> src/time.rs:59:1 | 59 | impl Into<KiloHertz> for MegaHertz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider to implement `From<time::MegaHertz>` instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> src/watchdog.rs:69:1 | 69 | impl Into<IwdgTimeout> for Hertz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider to implement `From<time::Hertz>` instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into warning: `stm32f0xx-hal` (lib) generated 6 warnings ``` Co-authored-by: Alex Martens <[email protected]>
2 parents ef2e1a9 + dbea59b commit 67452b4

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121

2222
- Add CAN bus abstraction based on the [bxcan] crate.
2323
- Add PWM output generation based on the timers.
24+
- Added `impl From<KiloHertz> for Hertz`
25+
- Added `impl From<MegaHertz> for Hertz`
26+
- Added `impl From<KiloHertz> for MegaHertz`
27+
- Added `impl From<Hertz> for IwdgTimeout`
2428

2529
[bxcan]: https://crates.io/crates/bxcan
2630

src/rcc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub enum HSEBypassMode {
5858
feature = "stm32f072",
5959
feature = "stm32f078",
6060
))]
61+
#[allow(clippy::upper_case_acronyms)]
6162
pub enum USBClockSource {
6263
#[cfg(feature = "stm32f070")]
6364
/// USB peripheral's tranceiver is disabled
@@ -89,6 +90,7 @@ mod inner {
8990
))]
9091
pub(super) const RCC_PLLSRC_PREDIV1_SUPPORT: bool = false;
9192

93+
#[allow(clippy::upper_case_acronyms)]
9294
pub(super) enum SysClkSource {
9395
HSI,
9496
/// High-speed external clock(freq,bypassed)
@@ -205,6 +207,7 @@ mod inner {
205207
))]
206208
pub(super) const RCC_PLLSRC_PREDIV1_SUPPORT: bool = false;
207209

210+
#[allow(clippy::upper_case_acronyms)]
208211
pub(super) enum SysClkSource {
209212
HSI,
210213
/// High-speed external clock(freq,bypassed)

src/time.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ impl U32Ext for u32 {
4444
}
4545
}
4646

47-
impl Into<Hertz> for KiloHertz {
48-
fn into(self) -> Hertz {
49-
Hertz(self.0 * 1_000)
47+
impl From<KiloHertz> for Hertz {
48+
fn from(khz: KiloHertz) -> Self {
49+
Hertz(khz.0 * 1_000)
5050
}
5151
}
5252

53-
impl Into<Hertz> for MegaHertz {
54-
fn into(self) -> Hertz {
55-
Hertz(self.0 * 1_000_000)
53+
impl From<MegaHertz> for Hertz {
54+
fn from(mhz: MegaHertz) -> Self {
55+
Hertz(mhz.0 * 1_000_000)
5656
}
5757
}
5858

59-
impl Into<KiloHertz> for MegaHertz {
60-
fn into(self) -> KiloHertz {
61-
KiloHertz(self.0 * 1_000)
59+
impl From<MegaHertz> for KiloHertz {
60+
fn from(mhz: MegaHertz) -> Self {
61+
KiloHertz(mhz.0 * 1_000)
6262
}
6363
}

src/watchdog.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ pub struct IwdgTimeout {
6666
reload: u16,
6767
}
6868

69-
impl Into<IwdgTimeout> for Hertz {
69+
impl From<Hertz> for IwdgTimeout {
7070
/// This converts the value so it's usable by the IWDG
7171
/// Due to conversion losses, the specified frequency is a maximum
7272
///
7373
/// It can also only represent values < 10000 Hertz
74-
fn into(self) -> IwdgTimeout {
75-
let mut time = 40_000 / 4 / self.0;
74+
fn from(hz: Hertz) -> Self {
75+
let mut time = 40_000 / 4 / hz.0;
7676
let mut psc = 0;
7777
let mut reload = 0;
7878
while psc < 7 {

0 commit comments

Comments
 (0)