From ff3ac68d159869d57e2cc190236d08c64e00b867 Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Tue, 10 Mar 2026 17:53:01 +0100 Subject: some clippy warnings --- src/main.rs | 23 ++++++++++++++--------- src/run/mod.rs | 16 ++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3cf6c2d..6b64f79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,8 @@ use crate::run::Executor; macro_rules! print { ($($x:tt)*) => {{ - write!(io::stdout(), $($x)*).unwrap(); + let res = write!(io::stdout(), $($x)*); + res.unwrap(); io::stdout().flush().unwrap(); }} } @@ -47,11 +48,15 @@ macro_rules! println { () => {{ println!("") }}; - ($($x:tt)*) => {{ - write!(io::stdout(), $($x)*).unwrap(); - write!(io::stdout(), "\r\n").unwrap(); - io::stdout().flush().unwrap(); - }}; + ($($x:tt)*) => { + { + let res = write!(io::stdout(), $($x)*); + res.unwrap(); + let res = write!(io::stdout(), "\r\n"); + res.unwrap(); + io::stdout().flush().unwrap(); + } + }; } fn completely_clear_screen() { @@ -125,7 +130,7 @@ impl Session { fn clear_prompt(&mut self) { cursor::move_cursor(Direction::Right, self.line.distance_from_right_end()); for _ in 0..self.line.len() { - write!(io::stdout(), "\x08 \x08").unwrap(); + print!("\x08 \x08"); } io::stdout().lock().flush().unwrap(); self.line.clear(); @@ -318,7 +323,7 @@ fn event_loop() { // Ctrl+L 12 => { clear_screen(); - write!(io::stdout(), "{}", se.prompt()).unwrap(); + print!("{}", se.prompt()); io::stdout().write_all(&se.line.into_bytes()).unwrap(); cursor::move_cursor(Direction::Left, se.line.distance_from_right_end()); io::stdout().lock().flush().unwrap(); @@ -374,7 +379,7 @@ fn event_loop() { suggestions.sort_by(|x, y| x.delta.cmp(&y.delta)); suggestions.dedup_by(|x, y| x.delta == y.delta); - if suggestions.len() == 0 { + if suggestions.is_empty() { continue; } diff --git a/src/run/mod.rs b/src/run/mod.rs index c7f4408..6234b96 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -49,7 +49,7 @@ impl ExecError { e => format!("I am surprised you can get this error here: {e:?}"), }, ExecError::IO(error) => format!("{error:?}"), - ExecError::Panic => format!("worker thread panicked"), + ExecError::Panic => String::from("worker thread panicked"), ExecError::ErrorStack(stack) => { let mut out = String::new(); for e in stack.iter() { @@ -98,9 +98,9 @@ pub enum Output { File(File), } -impl Into for Input { - fn into(self) -> Stdio { - match self { +impl From for Stdio { + fn from(value: Input) -> Self { + match value { Input::Stdin => Stdio::inherit(), Input::Pipe(reader) => reader.into(), Input::File(file) => file.into(), @@ -108,9 +108,9 @@ impl Into for Input { } } -impl Into for Output { - fn into(self) -> Stdio { - match self { +impl From for Stdio { + fn from(value: Output) -> Stdio { + match value { Output::Stdout => Stdio::inherit(), Output::Pipe(writer) => writer.into(), Output::File(file) => file.into(), @@ -399,7 +399,7 @@ pub fn run(se: Arc>, cmd: Vec) { Ok(p) => p, Err(err) => { se.lock().unwrap().raw.disable(); - println!("{:?}: {}", err.0, String::from_utf8_lossy(&err.1)); + println!("{:?}: {}", err.0, String::from_utf8_lossy(err.1)); print!("{}", se.lock().unwrap().prompt()); std::io::stdout().lock().flush().unwrap(); se.lock().unwrap().raw.enable(); -- cgit v1.2.3