Apply some clippy lints

Nothing too surprising, mostly removing useless references and lambdas
This commit is contained in:
Fabian Boehm 2024-05-26 10:37:37 +02:00
parent 2c3894993f
commit 20830744a9
8 changed files with 11 additions and 16 deletions

View File

@ -45,7 +45,7 @@ impl StringSubCommand<'_> for Length {
let val = &line;
val.split('\r')
} {
let n = width_without_escapes(&reset, 0);
let n = width_without_escapes(reset, 0);
max = usize::max(max, n);
}
if max > 0 {

View File

@ -108,7 +108,7 @@ impl<'args> StringSubCommand<'args> for Shorten<'args> {
inputs.push(s);
} else {
for s in splits {
let width = width_without_escapes(&s, 0);
let width = width_without_escapes(s, 0);
if width > 0 && width < min_width {
min_width = width;
}

View File

@ -363,14 +363,14 @@ impl EnvStack {
pub fn globals() -> &'static EnvStack {
use std::sync::OnceLock;
static GLOBALS: OnceLock<EnvStack> = OnceLock::new();
GLOBALS.get_or_init(|| EnvStack::new())
GLOBALS.get_or_init(EnvStack::new)
}
/// Access the principal variable stack, associated with the principal parser.
pub fn principal() -> &'static Arc<EnvStack> {
use std::sync::OnceLock;
static PRINCIPAL_STACK: OnceLock<Arc<EnvStack>> = OnceLock::new();
&PRINCIPAL_STACK.get_or_init(|| Arc::new(EnvStack::new()))
PRINCIPAL_STACK.get_or_init(|| Arc::new(EnvStack::new()))
}
pub fn set_argv(&self, argv: Vec<WString>) {

View File

@ -255,11 +255,7 @@ fn escape_yaml_fish_2_0(s: &mut Vec<u8>) {
fn maybe_unescape_yaml_fish_2_0(s: &[u8]) -> Cow<[u8]> {
// This is faster than s.contains(b'\\') and can be auto-vectorized to SIMD. See benchmark note
// on unescape_yaml_fish_2_0().
if !s
.into_iter()
.copied()
.fold(false, |acc, b| acc | (b == b'\\'))
{
if !s.iter().copied().fold(false, |acc, b| acc | (b == b'\\')) {
return s.into();
}
unescape_yaml_fish_2_0(s).into()
@ -412,7 +408,7 @@ fn decode_item_fish_2_0(mut data: &[u8]) -> Option<HistoryItem> {
// We're going to consume this line.
data = &data[advance..];
let line = maybe_unescape_yaml_fish_2_0(&line);
let line = maybe_unescape_yaml_fish_2_0(line);
paths.push(str2wcstring(&line));
}
}

View File

@ -58,7 +58,7 @@ impl<'a> OperationContext<'a> {
pub fn empty() -> OperationContext<'static> {
use std::sync::OnceLock;
static NULL_ENV: OnceLock<EnvStack> = OnceLock::new();
let null_env = NULL_ENV.get_or_init(|| EnvStack::new());
let null_env = NULL_ENV.get_or_init(EnvStack::new);
OperationContext::background(null_env, EXPANSION_LIMIT_DEFAULT)
}

View File

@ -402,7 +402,7 @@ impl Parser {
pub fn principal_parser() -> &'static Parser {
use std::cell::OnceCell;
static PRINCIPAL: MainThread<OnceCell<ParserRef>> = MainThread::new(OnceCell::new());
&PRINCIPAL
PRINCIPAL
.get()
// The parser is !Send/!Sync and strictly single-threaded, but we can have
// multi-threaded access to its variables stack (why, though?) so EnvStack::principal()

View File

@ -321,15 +321,14 @@ fn path_get_path_core<S: AsRef<wstr>>(cmd: &wstr, pathsv: &[S]) -> GetPathResult
let p = p.as_ref();
p.starts_with("/mnt/")
&& p.chars()
.skip("/mnt/x".len())
.next()
.nth("/mnt/x".len())
.map(|c| c == '/')
.unwrap_or(false)
})
.count();
&pathsv[..pathsv.len() - win_path_count]
} else {
&pathsv
pathsv
};
let mut best = noent_res;

View File

@ -102,7 +102,7 @@ fn thread_id() -> usize {
fn test_thread_ids() {
let start_thread_id = thread_id();
assert_eq!(start_thread_id, thread_id());
let spawned_thread_id = std::thread::spawn(|| thread_id()).join();
let spawned_thread_id = std::thread::spawn(thread_id).join();
assert_ne!(start_thread_id, spawned_thread_id.unwrap());
}