Skip to content

Commit ba471c8

Browse files
authored
Fix clippy warnings and enforce -Dwarnings (#224)
This PR fixes existing clippy warnings and adds `-Dwarnings` to the clippy invocations of the justfile. I used the CLI args rather than RUSTFLAGS as there can be some issues with overriding other rustflags used. See rust-lang/cargo#8424 for more context re: rustflags issues
1 parent 37316f6 commit ba471c8

File tree

18 files changed

+61
-24
lines changed

18 files changed

+61
-24
lines changed

justfile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ _rustflags := env_var_or_default("RUSTFLAGS", "")
1515

1616
# If we're running in Github Actions and cargo-action-fmt is installed, then add
1717
# a command suffix that formats errors.
18-
_fmt := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "" } else {
18+
#
19+
# Clippy version also gets -Dwarnings.
20+
_fmt_clippy := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "-- -Dwarnings" } else {
21+
```
22+
if command -v cargo-action-fmt >/dev/null 2>&1; then
23+
echo "--message-format=json -- -Dwarnings | cargo-action-fmt"
24+
fi
25+
```
26+
}
27+
28+
_fmt_check_doc := if env_var_or_default("GITHUB_ACTIONS", "") != "true" { "" } else {
1929
```
2030
if command -v cargo-action-fmt >/dev/null 2>&1; then
2131
echo "--message-format=json | cargo-action-fmt"
@@ -47,27 +57,28 @@ default:
4757
check: && (check-crate _d1_pkg) (check-crate _espbuddy_pkg) (check-crate _x86_bootloader_pkg)
4858
{{ _cargo }} check \
4959
--lib --bins --examples --tests --benches \
50-
{{ _fmt }}
60+
{{ _fmt_check_doc }}
5161

5262
# check a crate.
5363
check-crate crate:
5464
{{ _cargo }} check \
5565
--lib --bins --examples --tests --benches --all-features \
5666
--package {{ crate }} \
57-
{{ _fmt }}
67+
{{ _fmt_check_doc }}
5868

5969
# run Clippy checks for all crates, across workspaces.
6070
clippy: && (clippy-crate _d1_pkg) (clippy-crate _espbuddy_pkg) (clippy-crate _x86_bootloader_pkg)
6171
{{ _cargo }} clippy \
6272
--lib --bins --examples --tests --benches --all-features \
63-
{{ _fmt }}
73+
{{ _fmt_clippy }}
6474

6575
# run clippy checks for a crate.
76+
# NOTE: -Dwarnings is added by _fmt because reasons
6677
clippy-crate crate:
6778
{{ _cargo }} clippy \
6879
--lib --bins --examples --tests --benches \
6980
--package {{ crate }} \
70-
{{ _fmt }}
81+
{{ _fmt_clippy }}
7182

7283
# test all packages, across workspaces
7384
test: (_get-cargo-command "nextest" "cargo-nextest" no-nextest)
@@ -138,7 +149,7 @@ docs *FLAGS:
138149
{{ _cargo }} doc \
139150
--all-features \
140151
{{ FLAGS }} \
141-
{{ _fmt }}
152+
{{ _fmt_check_doc }}
142153

143154
_get-cargo-command name pkg skip='':
144155
#!/usr/bin/env bash
@@ -158,4 +169,4 @@ _get-cargo-command name pkg skip='':
158169
err "missing cargo-{{ name }} executable"
159170
if confirm " install it?"; then
160171
cargo install {{ pkg }}
161-
fi
172+
fi

platforms/allwinner-d1/boards/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::Path;
66
fn main() {
77
let out_dir = env::var("OUT_DIR").expect("No out dir");
88
let dest_path = Path::new(&out_dir);
9-
let mut f = File::create(&dest_path.join("memory.x")).expect("Could not create file");
9+
let mut f = File::create(dest_path.join("memory.x")).expect("Could not create file");
1010

1111
f.write_all(include_bytes!("memory.x"))
1212
.expect("Could not write file");

platforms/allwinner-d1/boards/src/bin/mq-pro.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ fn main() -> ! {
128128
d1.run()
129129
}
130130

131+
// Note: pass by ref mut to enforce exclusive access
132+
#[allow(clippy::needless_pass_by_ref_mut)]
131133
fn init_i2c_puppet_irq(gpio: &mut d1_pac::GPIO, plic: &mut Plic) -> &'static WaitCell {
132134
use d1_pac::Interrupt;
133135
use mnemos_d1_core::plic::Priority;

platforms/allwinner-d1/core/src/clint.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ impl Clint {
2121
self.clint
2222
}
2323

24+
/// Summon the clint peripheral
25+
///
26+
/// # Safety
27+
///
28+
/// This is intended for use in interrupt context. Care should be taken not to have
29+
/// multiple instances live at the same time that may race or cause other UB issues
2430
#[must_use]
2531
pub unsafe fn summon() -> Self {
2632
Self {

platforms/allwinner-d1/core/src/drivers/spim.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// Spi Sender
1+
// Note: We sometimes force a pass by ref mut to enforce exclusive access
2+
#![allow(clippy::needless_pass_by_ref_mut)]
3+
4+
//! Spi Sender
25
36
use core::ptr::NonNull;
47

platforms/allwinner-d1/core/src/drivers/twi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Note: We sometimes force a pass by ref mut to enforce exclusive access
2+
#![allow(clippy::needless_pass_by_ref_mut)]
3+
14
//! Drivers for the Allwinner D1's I²C/TWI peripherals.
25
//!
36
//! This module contains an implementation of a driver for controlling the

platforms/allwinner-d1/core/src/drivers/uart.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Note: We sometimes force a pass by ref mut to enforce exclusive access
2+
#![allow(clippy::needless_pass_by_ref_mut)]
3+
14
use d1_pac::{GPIO, UART0};
25

36
use core::{

platforms/beepy/src/i2c_puppet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub enum RegistrationError {
241241
// https://github.com/solderparty/i2c_puppet#protocol
242242
const ADDR: u8 = 0x1f;
243243

244-
//// i2c_puppet I2C registers
244+
/// i2c_puppet I2C registers
245245
mod reg {
246246
/// To write with a register, we must OR the register number with this mask:
247247
/// <https://github.com/solderparty/i2c_puppet#protocol>

platforms/esp32c3-buddy/src/bin/qtpy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() -> ! {
4040

4141
let k = mnemos_esp32c3_buddy::init();
4242
mnemos_esp32c3_buddy::spawn_serial(
43-
&k,
43+
k,
4444
peripherals.USB_DEVICE,
4545
&mut system.peripheral_clock_control,
4646
);
@@ -51,5 +51,5 @@ fn main() -> ! {
5151
// Alarm 1 will be used to generate "sleep until" interrupts.
5252
let alarm1 = syst.alarm1;
5353

54-
mnemos_esp32c3_buddy::run(&k, alarm1)
54+
mnemos_esp32c3_buddy::run(k, alarm1)
5555
}

platforms/esp32c3-buddy/src/bin/xiao.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> ! {
4141

4242
mnemos_esp32c3_buddy::spawn_daemons(k);
4343
mnemos_esp32c3_buddy::spawn_serial(
44-
&k,
44+
k,
4545
peripherals.USB_DEVICE,
4646
&mut system.peripheral_clock_control,
4747
);
@@ -51,5 +51,5 @@ fn main() -> ! {
5151
// Alarm 1 will be used to generate "sleep until" interrupts.
5252
let alarm1 = syst.alarm1;
5353

54-
mnemos_esp32c3_buddy::run(&k, alarm1)
54+
mnemos_esp32c3_buddy::run(k, alarm1)
5555
}

0 commit comments

Comments
 (0)