Skip to content

Commit

Permalink
Merge pull request #801 from gwenn/expect
Browse files Browse the repository at this point in the history
Use #[expect(lint)] where possible
  • Loading branch information
gwenn authored Sep 29, 2024
2 parents 547a9a0 + 35f48a9 commit 2729709
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ impl FilenameCompleter {
/// partial path to be completed.
pub fn complete_path(&self, line: &str, pos: usize) -> Result<(usize, Vec<Pair>)> {
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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 7 additions & 10 deletions src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<()>;
Expand Down Expand Up @@ -474,7 +473,7 @@ impl<'b> InputState<'b> {
wrt: &mut dyn Refresher,
digit: char,
) -> Result<KeyEvent> {
#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
match digit {
'0'..='9' => {
self.num_args = digit.to_digit(10).unwrap() as i16;
Expand All @@ -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 {
Expand Down Expand Up @@ -657,7 +656,7 @@ impl<'b> InputState<'b> {
Ok(cmd)
}

#[allow(clippy::cast_possible_truncation)]
#[expect(clippy::cast_possible_truncation)]
fn vi_arg_digit<R: RawReader>(
&mut self,
rdr: &mut R,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fn reverse_incremental_search<H: Helper, I: History>(

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;
Expand Down Expand Up @@ -596,7 +596,6 @@ pub struct Editor<H: Helper, I: History> {
/// Default editor with no helper and `DefaultHistory`
pub type DefaultEditor = Editor<(), DefaultHistory>;

#[allow(clippy::new_without_default)]
impl<H: Helper> Editor<H, DefaultHistory> {
/// Create an editor with the default configuration
pub fn new() -> Result<Self> {
Expand Down
4 changes: 2 additions & 2 deletions src/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -377,7 +376,7 @@ impl PosixRawReader {
}

/// Handle \E[ <seq2:digit> escape sequences
#[allow(clippy::cognitive_complexity)]
#[expect(clippy::cognitive_complexity)]
fn extended_escape(&mut self, seq2: char) -> Result<KeyEvent> {
let seq3 = self.next_char()?;
if seq3 == '~' {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tty/windows.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 2729709

Please sign in to comment.