Skip to content

Commit

Permalink
style(clippy): fix all new clippy errors with 'rustc:1.73.0' (#111)
Browse files Browse the repository at this point in the history
Also updating `proc-macro2` because of rust-lang/rust#113152
makes the build fail on nightly.
  • Loading branch information
woshilapin committed Oct 27, 2023
1 parent 7c190c2 commit 6182434
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 10 additions & 18 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl App {
.items
.iter()
.map(|(_, text)| text.width())
.chain(vec![block_title.width()].into_iter())
.chain(vec![block_title.width()])
.max()
.map(|v| v as f32 + 7.)
{
Expand Down Expand Up @@ -731,32 +731,24 @@ mod tests {
let backend = TestBackend::new(20, 10);
let mut terminal = Terminal::new(backend).unwrap();
terminal
.draw(|mut f| {
.draw(|f| {
let size = f.size();
app.selected_block = Block::UserInput;
app.draw_user_input(
&mut f,
size,
&Events::new(100, &kernel_logs).tx,
);
app.draw_kernel_info(
&mut f,
size,
&info::KernelInfo::new().current_info,
);
app.draw_user_input(f, size, &Events::new(100, &kernel_logs).tx);
app.draw_kernel_info(f, size, &info::KernelInfo::new().current_info);
app.input_query = String::from("a");
app.draw_kernel_modules(&mut f, size, &mut kernel_modules);
app.draw_module_info(&mut f, size, &mut kernel_modules);
app.draw_kernel_activities(&mut f, size, &mut kernel_logs);
app.draw_kernel_modules(f, size, &mut kernel_modules);
app.draw_module_info(f, size, &mut kernel_modules);
app.draw_kernel_activities(f, size, &mut kernel_logs);
})
.unwrap();
}
#[test]
fn test_input_mode() {
let mut input_mode = InputMode::Load;
assert_eq!(false, input_mode.is_none());
assert_eq!(true, input_mode.to_string().contains("Load"));
assert!(!input_mode.is_none());
assert!(input_mode.to_string().contains("Load"));
input_mode = InputMode::None;
assert_eq!(true, input_mode.to_string().contains("Search"));
assert!(input_mode.to_string().contains("Search"));
}
}
8 changes: 3 additions & 5 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ mod tests {
loop {
let tx = events.tx.clone();
thread::spawn(move || {
match tx.send(Event::Input(Key::Char(
let _ = tx.send(Event::Input(Key::Char(
std::char::from_digit(i, 10).unwrap_or('x'),
))) {
_ => {}
};
)));
});
i += 1;
match events.rx.recv()? {
Expand All @@ -103,7 +101,7 @@ mod tests {
}
}
Event::Tick => thread::sleep(Duration::from_millis(100)),
Event::Kernel(log) => assert_ne!(true, log.is_empty()),
Event::Kernel(log) => assert!(!log.is_empty()),
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod tests {
#[test]
fn test_module_command() {
let module_command = ModuleCommand::None;
assert_eq!(true, module_command == ModuleCommand::None);
assert!(module_command == ModuleCommand::None);

assert_ne!("", ModuleCommand::None.get("test").title);
assert_ne!("", ModuleCommand::Load.get("module").desc);
Expand Down
6 changes: 3 additions & 3 deletions src/kernel/lkm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,15 @@ mod tests {
kernel_modules
.set_current_command(ModuleCommand::Load, String::from("test"));
assert_eq!("test", kernel_modules.current_name);
assert_eq!(false, kernel_modules.execute_command());
assert!(!kernel_modules.execute_command());
kernel_modules.set_current_command(ModuleCommand::Load, String::new());
kernel_modules.scroll_list(ScrollDirection::Top);
for command in vec![
for command in [
ModuleCommand::Unload,
ModuleCommand::Blacklist,
ModuleCommand::None,
] {
kernel_modules.set_current_command(command.clone(), String::new());
kernel_modules.set_current_command(command, String::new());
assert_eq!(!command.is_none(), kernel_modules.cancel_execution());
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/kernel/log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::app::ScrollDirection;
use crate::util;
use std::fmt::Write as _;

/* Kernel activity logs */
#[derive(Clone, Debug, Default)]
Expand All @@ -24,12 +25,11 @@ impl KernelLogs {
)
.unwrap_or_else(|_| String::from("failed to retrieve dmesg output"));
let logs_updated =
self.output.lines().rev().next().unwrap_or_default() != self.last_line;
self.output.lines().next_back().unwrap_or_default() != self.last_line;
self.last_line = self
.output
.lines()
.rev()
.next()
.next_back()
.unwrap_or_default()
.to_string();
logs_updated
Expand Down Expand Up @@ -67,8 +67,10 @@ impl KernelLogs {
})
.unwrap_or(0),
)
.map(|i| format!("{i}\n"))
.collect::<String>();
.fold(String::new(), |mut s, i| {
let _ = writeln!(s, "{i}");
s
});
&self.selected_output
}

Expand Down Expand Up @@ -114,7 +116,7 @@ mod tests {
{
kernel_logs.scroll(*direction, *direction == ScrollDirection::Top);
}
assert_eq!(true, kernel_logs.update());
assert!(kernel_logs.update());
assert_ne!(0, kernel_logs.output.lines().count());
assert_ne!(0, kernel_logs.select(10, 2).len());
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ mod tests {
let tx = events.tx.clone();
thread::spawn(move || {
/* Test the general keys. */
for key in vec![
for key in [
Key::Char('?'),
Key::Ctrl('t'),
Key::Ctrl('b'),
Expand Down Expand Up @@ -604,10 +604,10 @@ mod tests {
}
send_key(&tx, Key::Char('r'));
/* Test the switch keys. */
for arrow_key in vec![Key::Right, Key::Left] {
for selected_key in vec![arrow_key; Block::CARDINALITY] {
for arrow_key in [Key::Right, Key::Left] {
for selected_key in [arrow_key; Block::CARDINALITY] {
send_key(&tx, selected_key);
for key in vec![
for key in [
Key::Up,
Key::Down,
Key::Down,
Expand All @@ -621,7 +621,7 @@ mod tests {
}
}
/* Test the input mode keys. */
for key in vec![
for key in [
Key::Char('v'),
Key::Delete,
Key::Char('~'),
Expand Down
2 changes: 1 addition & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ mod tests {
let mut unicode = Unicode::new(true);
for symbol in unicode.symbols.clone() {
if symbol.0 != Symbol::Blank {
assert_eq!(true, symbol.1[1].len() < 2)
assert!(symbol.1[1].len() < 2)
}
}
unicode.replace = false;
Expand Down

0 comments on commit 6182434

Please sign in to comment.