From 35f48a9fc4c0e4e11e4083b2cf130238adaa2651 Mon Sep 17 00:00:00 2001 From: gwenn Date: Thu, 5 Sep 2024 20:04:28 +0200 Subject: [PATCH] Use #[expect(lint)] where possible --- src/completion.rs | 1 - src/error.rs | 2 +- src/keymap.rs | 17 +++++++---------- src/keys.rs | 1 - src/lib.rs | 3 +-- src/line_buffer.rs | 4 ++-- src/tty/mod.rs | 1 - src/tty/unix.rs | 8 +++----- src/tty/windows.rs | 2 +- 9 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/completion.rs b/src/completion.rs index 114d1aa9e..2d1971f01 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -211,7 +211,6 @@ impl FilenameCompleter { /// partial path to be completed. pub fn complete_path(&self, line: &str, pos: usize) -> Result<(usize, Vec)> { let (start, mut matches) = self.complete_path_unsorted(line, pos)?; - #[allow(clippy::unnecessary_sort_by)] matches.sort_by(|a, b| a.display().cmp(b.display())); Ok((start, matches)) } diff --git a/src/error.rs b/src/error.rs index b75101199..038ae4b2e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,7 +8,7 @@ use std::io; /// The error type for Rustyline errors that can arise from /// I/O related errors or Errno when using the nix-rust library // #[non_exhaustive] -#[allow(clippy::module_name_repetitions)] +#[expect(clippy::module_name_repetitions)] #[derive(Debug)] #[non_exhaustive] pub enum ReadlineError { diff --git a/src/keymap.rs b/src/keymap.rs index 784c91016..8564c163a 100644 --- a/src/keymap.rs +++ b/src/keymap.rs @@ -131,7 +131,6 @@ impl Cmd { /// Tells if current command should reset kill ring. #[must_use] pub const fn should_reset_kill_ring(&self) -> bool { - #[allow(clippy::match_same_arms)] match *self { Self::Kill(Movement::BackwardChar(_) | Movement::ForwardChar(_)) => true, Self::ClearScreen @@ -347,7 +346,7 @@ pub enum InputMode { /// Transform key(s) to commands based on current input mode pub struct InputState<'b> { pub(crate) mode: EditMode, - #[cfg_attr(not(feature = "custom-bindings"), allow(dead_code))] + #[cfg_attr(not(feature = "custom-bindings"), expect(dead_code))] custom_bindings: &'b Bindings, pub(crate) input_mode: InputMode, // vi only ? // numeric arguments: http://web.mit.edu/gnu/doc/html/rlman_1.html#SEC7 @@ -389,12 +388,12 @@ pub trait Refresher { /// Returns `true` if there is a hint displayed. fn has_hint(&self) -> bool; /// Returns the hint text that is shown after the current cursor position. - #[cfg_attr(not(feature = "custom-bindings"), allow(dead_code))] + #[cfg_attr(not(feature = "custom-bindings"), expect(dead_code))] fn hint_text(&self) -> Option<&str>; /// currently edited line fn line(&self) -> &str; /// Current cursor position (byte position) - #[cfg_attr(not(feature = "custom-bindings"), allow(dead_code))] + #[cfg_attr(not(feature = "custom-bindings"), expect(dead_code))] fn pos(&self) -> usize; /// Display `msg` above currently edited line. fn external_print(&mut self, msg: String) -> Result<()>; @@ -474,7 +473,7 @@ impl<'b> InputState<'b> { wrt: &mut dyn Refresher, digit: char, ) -> Result { - #[allow(clippy::cast_possible_truncation)] + #[expect(clippy::cast_possible_truncation)] match digit { '0'..='9' => { self.num_args = digit.to_digit(10).unwrap() as i16; @@ -487,7 +486,7 @@ impl<'b> InputState<'b> { loop { wrt.refresh_prompt_and_line(&format!("(arg: {}) ", self.num_args))?; let key = rdr.next_key(true)?; - #[allow(clippy::cast_possible_truncation)] + #[expect(clippy::cast_possible_truncation)] match key { E(K::Char(digit @ '0'..='9'), m) if m == M::NONE || m == M::ALT => { if self.num_args == -1 { @@ -657,7 +656,7 @@ impl<'b> InputState<'b> { Ok(cmd) } - #[allow(clippy::cast_possible_truncation)] + #[expect(clippy::cast_possible_truncation)] fn vi_arg_digit( &mut self, rdr: &mut R, @@ -911,7 +910,6 @@ impl<'b> InputState<'b> { }; debug!(target: "rustyline", "Vi insert: {:?}", cmd); if cmd.is_repeatable_change() { - #[allow(clippy::if_same_then_else)] if let (Cmd::Replace(..), Cmd::SelfInsert(..)) = (&self.last_cmd, &cmd) { // replacing... } else if let (Cmd::SelfInsert(..), Cmd::SelfInsert(..)) = (&self.last_cmd, &cmd) { @@ -1101,7 +1099,7 @@ impl<'b> InputState<'b> { num_args } - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss)] fn emacs_num_args(&mut self) -> (RepeatCount, bool) { let num_args = self.num_args(); if num_args < 0 { @@ -1115,7 +1113,6 @@ impl<'b> InputState<'b> { } } - #[allow(clippy::cast_sign_loss)] fn vi_num_args(&mut self) -> RepeatCount { let num_args = self.num_args(); if num_args < 0 { diff --git a/src/keys.rs b/src/keys.rs index b8c378628..7135d385d 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -24,7 +24,6 @@ impl KeyEvent { } return E(K::Char(c), mods); } - #[allow(clippy::match_same_arms)] match c { '\x00' => E(K::Char('@'), mods | M::CTRL), // '\0' '\x01' => E(K::Char('A'), mods | M::CTRL), diff --git a/src/lib.rs b/src/lib.rs index 10fd4b68a..388696f1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -444,7 +444,7 @@ fn reverse_incremental_search( struct Guard<'m>(&'m tty::Mode); -#[allow(unused_must_use)] +#[expect(unused_must_use)] impl Drop for Guard<'_> { fn drop(&mut self) { let Guard(mode) = *self; @@ -596,7 +596,6 @@ pub struct Editor { /// Default editor with no helper and `DefaultHistory` pub type DefaultEditor = Editor<(), DefaultHistory>; -#[allow(clippy::new_without_default)] impl Editor { /// Create an editor with the default configuration pub fn new() -> Result { diff --git a/src/line_buffer.rs b/src/line_buffer.rs index ac9c68821..3f2dda9a5 100644 --- a/src/line_buffer.rs +++ b/src/line_buffer.rs @@ -1115,7 +1115,7 @@ impl LineBuffer { .map_or_else(|| self.buf.len(), |pos| end + pos); let mut index = start; if dedent { - #[allow(clippy::unnecessary_to_owned)] + #[expect(clippy::unnecessary_to_owned)] for line in self.buf[start..end].to_string().split('\n') { let max = line.len() - line.trim_start().len(); let deleting = min(max, amount); @@ -1131,7 +1131,7 @@ impl LineBuffer { index += line.len() + 1 - deleting; } } else { - #[allow(clippy::unnecessary_to_owned)] + #[expect(clippy::unnecessary_to_owned)] for line in self.buf[start..end].to_string().split('\n') { for off in (0..amount).step_by(INDENT.len()) { self.insert_str(index, &INDENT[..min(amount - off, INDENT.len())], cl); diff --git a/src/tty/mod.rs b/src/tty/mod.rs index 62484f042..d5a0c7cf9 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -46,7 +46,6 @@ pub trait Renderer { fn move_cursor(&mut self, old: Position, new: Position) -> Result<()>; /// Display `prompt`, line and cursor in terminal output - #[allow(clippy::too_many_arguments)] fn refresh_line( &mut self, prompt: &str, diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 08d754810..2800af617 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -41,7 +41,6 @@ const BRACKETED_PASTE_OFF: &str = "\x1b[?2004l"; nix::ioctl_read_bad!(win_size, libc::TIOCGWINSZ, libc::winsize); -#[allow(clippy::useless_conversion)] fn get_win_size(fd: RawFd) -> (usize, usize) { use std::mem::zeroed; @@ -158,7 +157,7 @@ impl Read for TtyIn { return Err(error); } } else { - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss)] return Ok(res as usize); } } @@ -377,7 +376,7 @@ impl PosixRawReader { } /// Handle \E[ escape sequences - #[allow(clippy::cognitive_complexity)] + #[expect(clippy::cognitive_complexity)] fn extended_escape(&mut self, seq2: char) -> Result { let seq3 = self.next_char()?; if seq3 == '~' { @@ -1328,7 +1327,6 @@ impl Term for PosixTerminal { ) }; let unsupported = is_unsupported_term(); - #[allow(unused_variables)] let sigwinch = if !unsupported && is_in_a_tty && is_out_a_tty { Some(SigWinCh::install_sigwinch_handler()?) } else { @@ -1471,7 +1469,7 @@ impl Term for PosixTerminal { } } -#[allow(unused_must_use)] +#[expect(unused_must_use)] impl Drop for PosixTerminal { fn drop(&mut self) { if self.close_on_drop { diff --git a/src/tty/windows.rs b/src/tty/windows.rs index 7574403f0..02cf69a4b 100644 --- a/src/tty/windows.rs +++ b/src/tty/windows.rs @@ -1,5 +1,5 @@ //! Windows specific definitions -#![allow(clippy::try_err)] // suggested fix does not work (cannot infer...) +#![expect(clippy::try_err)] // suggested fix does not work (cannot infer...) use std::fs::OpenOptions; use std::io;