From fae780d666102396a02a0b95f0a7a16ac8e5e155 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Fri, 12 Jan 2024 20:31:07 +0100 Subject: [PATCH] clippy There are a bunch more now that widestrs is gone --- src/ast.rs | 8 ++++---- src/builtins/wait.rs | 21 +++++++++------------ src/common.rs | 2 +- src/env/environment_impl.rs | 5 ++--- src/future_feature_flags.rs | 2 +- src/path.rs | 8 ++++---- src/proc.rs | 4 ++-- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 335896b39..e15507576 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -2803,10 +2803,10 @@ impl<'s> NodeVisitorMut for Populator<'s> { return; }; - /// We believe the node is some sort of block statement. Attempt to find a source range - /// for the block's keyword (for, if, etc) and a user-presentable description. This - /// is used to provide better error messages. Note at this point the parse tree is - /// incomplete; in particular parent nodes are not set. + // We believe the node is some sort of block statement. Attempt to find a source range + // for the block's keyword (for, if, etc) and a user-presentable description. This + // is used to provide better error messages. Note at this point the parse tree is + // incomplete; in particular parent nodes are not set. let mut cursor = node; let header = loop { match cursor.typ() { diff --git a/src/builtins/wait.rs b/src/builtins/wait.rs index 28316275b..d535e2596 100644 --- a/src/builtins/wait.rs +++ b/src/builtins/wait.rs @@ -150,11 +150,11 @@ pub fn wait(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt print_help = true; } ':' => { - builtin_missing_argument(parser, streams, cmd, &argv[w.woptind - 1], print_hints); + builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1], print_hints); return STATUS_INVALID_ARGS; } '?' => { - builtin_unknown_option(parser, streams, cmd, &argv[w.woptind - 1], print_hints); + builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1], print_hints); return STATUS_INVALID_ARGS; } _ => { @@ -176,15 +176,16 @@ pub fn wait(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt // Get the list of wait handles for our waiting. let mut wait_handles: Vec = Vec::new(); - for i in w.woptind..argc { - if iswnumeric(argv[i]) { + let optind = w.woptind; + for item in &argv[optind..argc] { + if iswnumeric(item) { // argument is pid - let mpid: Result = fish_wcstoi(argv[i]); + let mpid: Result = fish_wcstoi(item); if mpid.is_err() || mpid.unwrap() <= 0 { streams.err.append(wgettext_fmt!( "%ls: '%ls' is not a valid process id\n", cmd, - argv[i], + item, )); continue; } @@ -198,15 +199,11 @@ pub fn wait(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt } } else { // argument is process name - if !find_wait_handles( - WaitHandleQuery::ProcName(argv[i]), - parser, - &mut wait_handles, - ) { + if !find_wait_handles(WaitHandleQuery::ProcName(item), parser, &mut wait_handles) { streams.err.append(wgettext_fmt!( "%ls: Could not find child processes with the name '%ls'\n", cmd, - argv[i], + item, )); } } diff --git a/src/common.rs b/src/common.rs index 2691ac550..c6e715ae6 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1569,7 +1569,7 @@ pub fn reformat_for_screen(msg: &wstr, termsize: &Termsize) -> WString { } else { // Print the token. let token = &msg[start..pos]; - let line_width_unit = (if line_width != 0 { 1 } else { 0 }); + let line_width_unit = if line_width != 0 { 1 } else { 0 }; if (line_width + line_width_unit + tok_width) > screen_width { buff.push('\n'); line_width = 0; diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index d9e625196..f12a1e42c 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -350,7 +350,7 @@ impl EnvScopedImpl { } else if key == L!("history") { // Big hack. We only allow getting the history on the main thread. Note that history_t // may ask for an environment variable, so don't take the lock here (we don't need it). - if (!is_main_thread()) { + if !is_main_thread() { return None; } let history = commandline_get_state().history.unwrap_or_else(|| { @@ -369,8 +369,7 @@ impl EnvScopedImpl { )) } else if key == L!("pipestatus") { let js = &self.perproc_data.statuses; - let mut result = Vec::new(); - result.reserve(js.pipestatus.len()); + let mut result = Vec::with_capacity(js.pipestatus.len()); for i in &js.pipestatus { result.push(i.to_wstring()); } diff --git a/src/future_feature_flags.rs b/src/future_feature_flags.rs index b81376f9d..f4eaf22b0 100644 --- a/src/future_feature_flags.rs +++ b/src/future_feature_flags.rs @@ -154,7 +154,7 @@ impl Features { self.values[flag as usize].store(value, Ordering::SeqCst) } - fn set_from_string<'a>(&self, str: &wstr) { + fn set_from_string(&self, str: &wstr) { let whitespace = L!("\t\n\0x0B\0x0C\r ").as_char_slice(); for entry in str.as_char_slice().split(|c| *c == ',') { if entry.is_empty() { diff --git a/src/path.rs b/src/path.rs index 0c297648e..567786aea 100644 --- a/src/path.rs +++ b/src/path.rs @@ -76,7 +76,7 @@ pub fn path_emit_config_directory_messages(vars: &EnvStack) { if !data.success() { maybe_issue_path_warning( L!("data"), - &wgettext!("can not save history"), + wgettext!("can not save history"), data.used_xdg, L!("XDG_DATA_HOME"), &data.path, @@ -92,7 +92,7 @@ pub fn path_emit_config_directory_messages(vars: &EnvStack) { if !config.success() { maybe_issue_path_warning( L!("config"), - &wgettext!("can not save universal variables or functions"), + wgettext!("can not save universal variables or functions"), config.used_xdg, L!("XDG_CONFIG_HOME"), &config.path, @@ -705,13 +705,13 @@ fn path_remoteness(path: &wstr) -> DirRemoteness { fn get_data_directory() -> &'static BaseDirectory { static DIR: Lazy = Lazy::new(|| make_base_directory(L!("XDG_DATA_HOME"), L!("/.local/share/fish"))); - &*DIR + &DIR } fn get_config_directory() -> &'static BaseDirectory { static DIR: Lazy = Lazy::new(|| make_base_directory(L!("XDG_CONFIG_HOME"), L!("/.config/fish"))); - &*DIR + &DIR } /// Appends a path component, with a / if necessary. diff --git a/src/proc.rs b/src/proc.rs index 08f7c2503..0acff52eb 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -1605,10 +1605,10 @@ fn summary_command(j: &Job, p: Option<&Process>) -> WString { // Arguments are the signal name and description. let sig = Signal::new(p.status.signal_code()); buffer.push(' '); - buffer += &escape(&sig.name())[..]; + buffer += &escape(sig.name())[..]; buffer.push(' '); - buffer += &escape(&sig.desc())[..]; + buffer += &escape(sig.desc())[..]; // If we have multiple processes, we also append the pid and argv. if j.processes().len() > 1 {