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

+18-7
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

+1-1
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

+2
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

+6
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

+4-1
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

+3
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

+3
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

+1-1
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

+2-2
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

+2-2
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
}

platforms/esp32c3-buddy/src/heap.rs

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ impl UnderlyingAllocator for UnderlyingEspHeap {
3838
///
3939
/// May or may not require a call to [UnderlyingAllocator::init()] before the allocator
4040
/// is actually ready for use.
41+
//
42+
// clippy note: <https://rust-lang.github.io/rust-clippy/master/index.html#/declare_interior_mutable_const>
43+
//
44+
// > A “non-constant” const item is a legacy way to supply an initialized value to
45+
// > downstream static items (e.g., the std::sync::ONCE_INIT constant). In this
46+
// > case the use of const is legit, and this lint should be suppressed.
47+
#[allow(clippy::declare_interior_mutable_const)]
4148
const INIT: Self = UnderlyingEspHeap(EspHeap::empty());
4249

4350
/// Initialize the allocator, if it is necessary to populate with a region

platforms/esp32c3-buddy/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn run(k: &'static Kernel, alarm1: Alarm<Target, 1>) -> ! {
101101
// Timer is downcounting
102102
let elapsed = SystemTimer::now() - start;
103103

104-
let turn = k.timer().force_advance_ticks(elapsed as u64 / 2u64);
104+
let turn = k.timer().force_advance_ticks(elapsed / 2u64);
105105

106106
// If there is nothing else scheduled, and we didn't just wake something up,
107107
// sleep for some amount of time
@@ -138,7 +138,7 @@ pub fn run(k: &'static Kernel, alarm1: Alarm<Target, 1>) -> ! {
138138
// Account for time slept
139139
let elapsed = SystemTimer::now() - wfi_start;
140140

141-
let _turn = k.timer().force_advance_ticks(elapsed as u64 / 2u64);
141+
let _turn = k.timer().force_advance_ticks(elapsed / 2u64);
142142
}
143143
}
144144
}

platforms/melpomene/src/sim_drivers/tcp_serial.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ impl TcpSerial {
6464

6565
let _hdl = tokio::spawn(
6666
async move {
67-
let mut handle = a_ring;
67+
let handle = a_ring;
6868
loop {
6969
match listener.accept().await {
7070
Ok((stream, addr)) => {
71-
process_stream(&mut handle, stream, irq.clone())
71+
process_stream(&handle, stream, irq.clone())
7272
.instrument(info_span!("process_stream", client.addr = %addr))
7373
.await
7474
}
@@ -88,7 +88,7 @@ impl TcpSerial {
8888
}
8989
}
9090

91-
async fn process_stream(handle: &mut BidiHandle, mut stream: TcpStream, irq: Arc<Notify>) {
91+
async fn process_stream(handle: &BidiHandle, mut stream: TcpStream, irq: Arc<Notify>) {
9292
loop {
9393
// Wait until either the socket has data to read, or the other end of
9494
// the BBQueue has data to write.
@@ -111,7 +111,7 @@ async fn process_stream(handle: &mut BidiHandle, mut stream: TcpStream, irq: Arc
111111
// Try to read data, this may still fail with `WouldBlock`
112112
// if the readiness event is a false positive.
113113
match stream.try_read(&mut in_grant) {
114-
Ok(used) if used == 0 => {
114+
Ok(0) => {
115115
warn!("Empty read, socket probably closed.");
116116
return;
117117
},

platforms/x86_64/core/src/bin/bootloader/framebuf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(super) unsafe fn mk_framebuf() -> FramebufWriter {
3535
/// This forcibly unlocks a potentially-locked mutex, violating mutual
3636
/// exclusion! This should only be called in conditions where no other CPU core
3737
/// will *ever* attempt to access the framebuffer again (such as while oopsing).
38+
#[allow(dead_code)]
3839
pub(super) unsafe fn force_unlock() {
3940
if let Some((_, fb)) = FRAMEBUFFER.try_get() {
4041
fb.force_unlock();

platforms/x86_64/core/src/bin/bootloader/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn kernel_start(info: &'static mut bootloader_api::BootInfo) -> ! {
6464

6565
#[cold]
6666
#[cfg_attr(target_os = "none", panic_handler)]
67+
#[allow(dead_code)]
6768
fn panic(panic: &core::panic::PanicInfo<'_>) -> ! {
6869
use core::fmt::Write;
6970
use embedded_graphics::{

platforms/x86_64/core/src/drivers/framebuf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
// if we have reached the bottom of the screen, we'll need to scroll
7474
// previous framebuffer contents up to make room for new line(s) of
7575
// text.
76-
self.point.y = self.point.y + self.style.font.character_size.height as i32;
76+
self.point.y += self.style.font.character_size.height as i32;
7777
self.point.x = self.start_x;
7878
}
7979
}
@@ -133,7 +133,7 @@ where
133133
// line, wrap the line.
134134
let rem = self.px_to_len(self.width_px - (self.point.x as u32));
135135
if line.len() > rem {
136-
let (curr, next) = line.split_at(rem as usize);
136+
let (curr, next) = line.split_at(rem);
137137
line = next;
138138
chunk = curr;
139139
has_newline = true;

platforms/x86_64/core/src/interrupt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl hal_core::interrupt::Handlers<Registers> for InterruptHandlers {
111111
C: interrupt::Context<Registers = Registers> + interrupt::ctx::CodeFault,
112112
{
113113
// TODO: add a nice fault handler
114-
let _fault = match cx.details() {
114+
match cx.details() {
115115
Some(deets) => panic!("code fault {}: \n{deets}", cx.fault_kind()),
116116
None => panic!("code fault {}!", cx.fault_kind()),
117117
};

platforms/x86_64/core/src/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ where
127127
}
128128
}) as &mut dyn tracing::field::Visit,
129129
);
130-
writeln!(&mut writer, "").unwrap();
130+
writeln!(&mut writer).unwrap();
131131

132132
self.point
133133
.store(pack_point(writer.next_point()), Ordering::Release);

0 commit comments

Comments
 (0)