Skip to content

Commit 2d672ad

Browse files
crawfxrdjackpot51
authored andcommitted
Fix clippy warnings on nightly
Fix warnings: - unused_variables - clippy::if_then_panic - clippy::or_fun_call - clippy::for_kv_map - clippy::needless_borrow Silence warnings: - clippy::match_single_binding - clippy::new_without_default - clippy::from_str_radix_10 - clippy::needless_range_loop Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent 3acc547 commit 2d672ad

8 files changed

Lines changed: 24 additions & 22 deletions

File tree

src/cmd/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn int(ec: &mut Ec, args: &[&str]) {
1010
return;
1111
}
1212

13-
let int = match u8::from_str_radix(&args[0], 10) {
13+
let int = match u8::from_str_radix(args[0], 10) {
1414
Ok(ok) => if ok <= 5 {
1515
ok
1616
} else {

src/cmd/kbc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn cmd(ec: &mut Ec, args: &[&str]) {
1717
return;
1818
}
1919

20-
let data = match u8::from_str_radix(&args[0], 16) {
20+
let data = match u8::from_str_radix(args[0], 16) {
2121
Ok(ok) => ok,
2222
Err(err) => {
2323
eprintln!("argument '{}' failed to parse as hex: {}", args[0], err);
@@ -55,7 +55,7 @@ pub fn write(ec: &mut Ec, args: &[&str]) {
5555
return;
5656
}
5757

58-
let data = match u8::from_str_radix(&args[0], 16) {
58+
let data = match u8::from_str_radix(args[0], 16) {
5959
Ok(ok) => ok,
6060
Err(err) => {
6161
eprintln!("argument '{}' failed to parse as hex: {}", args[0], err);

src/cmd/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: MIT
22

3+
#![allow(clippy::from_str_radix_10)]
4+
35
pub mod int;
46
pub mod kbc;
57
pub mod pmc;

src/cmd/pmc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn cmd(ec: &mut Ec, args: &[&str]) {
1616
return;
1717
}
1818

19-
let data = match u8::from_str_radix(&args[0], 16) {
19+
let data = match u8::from_str_radix(args[0], 16) {
2020
Ok(ok) => ok,
2121
Err(err) => {
2222
eprintln!("argument '{}' failed to parse as hex: {}", args[0], err);
@@ -44,7 +44,7 @@ pub fn write(ec: &mut Ec, args: &[&str]) {
4444
return;
4545
}
4646

47-
let data = match u8::from_str_radix(&args[0], 16) {
47+
let data = match u8::from_str_radix(args[0], 16) {
4848
Ok(ok) => ok,
4949
Err(err) => {
5050
eprintln!("argument '{}' failed to parse as hex: {}", args[0], err);

src/main.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct Completer<'a> {
2929
impl<'a> liner::Completer for Completer<'a> {
3030
fn completions(&mut self, start: &str) -> Vec<String> {
3131
let mut completions = Vec::new();
32-
for (name, _func) in self.commands {
32+
for name in self.commands.keys() {
3333
if name.starts_with(start) {
3434
completions.push(name.to_string());
3535
}
@@ -118,7 +118,7 @@ fn commands() -> CommandMap {
118118
};
119119

120120
mcu.xram[addr] = value;
121-
121+
122122
eprintln!("xram {:04X}: {:02X}", addr, mcu.xram[addr]);
123123
}
124124
} else {
@@ -164,9 +164,7 @@ fn timers(ec: &mut Ec) {
164164

165165
// Timer 0 running
166166
if tcon & 1 << 4 != 0 {
167-
if tmod & 0x0F != 0x01 {
168-
panic!("unimplemented TMOD 0x{:02X}", tmod);
169-
}
167+
assert!(tmod & 0x0F == 0x01, "unimplemented TMOD 0x{:02X}", tmod);
170168

171169
if ec.steps % 12 == 0 {
172170
let tl = 0x8A;
@@ -190,9 +188,7 @@ fn timers(ec: &mut Ec) {
190188

191189
// Timer 1 running
192190
if tcon & 1 << 6 != 0 {
193-
if tmod & 0xF0 != 0x10 {
194-
panic!("unimplemented TMOD 0x{:02X}", tmod);
195-
}
191+
assert!(tmod & 0xF0 == 0x10, "unimplemented TMOD 0x{:02X}", tmod);
196192

197193
if ec.steps % 12 == 0 {
198194
let tl = 0x8B;
@@ -222,7 +218,7 @@ fn main() {
222218
RUNNING.store(false, Ordering::SeqCst);
223219
}).expect("failed to set ctrl-c handler");
224220

225-
let pmem_path = env::args().nth(1).unwrap_or("ec.rom".to_string());
221+
let pmem_path = env::args().nth(1).unwrap_or_else(|| "ec.rom".to_string());
226222

227223
let mut pmem = fs::read(&pmem_path).expect("failed to read ec.rom");
228224

src/socket.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub fn socket_op(ec: &mut Ec, request: &[u8; 4]) -> [u8; 1] {
9898
},
9999
0x2f => {
100100
debug!(" (super io data 0x{:02X})", ec.superio_addr);
101+
#[allow(clippy::match_single_binding)]
101102
match ec.superio_addr {
102103
_ => {
103104
debug!(" (unimplemented)");

src/spi.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: MIT
22

3+
#![allow(clippy::needless_range_loop)]
4+
35
use std::collections::VecDeque;
46

57
#[cfg(feature = "debug_spi")]
@@ -20,6 +22,7 @@ pub struct Spi {
2022
pub output: VecDeque<u8>,
2123
}
2224

25+
#[allow(clippy::new_without_default)]
2326
impl Spi {
2427
pub fn new() -> Self {
2528
Self {
@@ -31,19 +34,19 @@ impl Spi {
3134
}
3235
}
3336

34-
pub fn step(&mut self, flash: &mut [u8], flash_name: &str) {
37+
pub fn step(&mut self, flash: &mut [u8], _flash_name: &str) {
3538
if let Some(command) = self.input.pop_front() {
36-
debug!("\n[spi {}", flash_name);
39+
debug!("\n[spi {}", _flash_name);
3740

3841
self.fast_read_addr = None;
3942

4043
match command {
4144
0x01 => {
4245
debug!(" write status");
4346

44-
let value = self.input.pop_front().expect("spi wrate status value missing");
47+
let _value = self.input.pop_front().expect("spi wrate status value missing");
4548

46-
debug!(" 0x{:02X}", value);
49+
debug!(" 0x{:02X}", _value);
4750
},
4851
0x02 => {
4952
debug!(" page program");

src/xram.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ pub fn xram(ec: &Ec, address: u16, new_opt: Option<u8>) -> u8 {
583583
// BRAM
584584
0x2200 ..= 0x22FF => {
585585
let base = 0x2200;
586-
let offset = address - base;
587-
debug!(" (BRAM 0x{:02X})", offset);
586+
let _offset = address - base;
587+
debug!(" (BRAM 0x{:02X})", _offset);
588588
},
589589
// PECI
590590
0x3000 ..= 0x30FF => {
@@ -632,8 +632,8 @@ pub fn xram(ec: &Ec, address: u16, new_opt: Option<u8>) -> u8 {
632632
},
633633
0x8000 ..= 0x97FF if ec.id == 0x5570 => {
634634
let base = 0x8000;
635-
let offset = address - base;
636-
debug!(" (SRAM 0x{:02X})", offset);
635+
let _offset = address - base;
636+
debug!(" (SRAM 0x{:02X})", _offset);
637637
}
638638
_ => panic!("xram unimplemented register 0x{:04X}", address),
639639
}

0 commit comments

Comments
 (0)