mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-11 20:48:49 +00:00
refactor: misc cleanup (#10998)
* refactor EnvVar: Arc<Box<[WString]>> -> Arc<[WString]> * remove unnecessary `&mut` from EnvVar methods * clippy: use eq_ignore_ascii_case instead of manual comparison see https://rust-lang.github.io/rust-clippy/master/index.html#manual_ignore_case_cmp * clippy: use `is_some_and` and `is_ok_and` instead of `map_or` see https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or * clippy: use `assert!()` instead of `assert_eq!()` with booleans
This commit is contained in:
parent
d842a6560e
commit
dcddffd222
10 changed files with 25 additions and 23 deletions
|
@ -84,7 +84,7 @@ fn smoke() {
|
|||
#[test]
|
||||
fn test_format_string_str() {
|
||||
let mut s: &str = "hello%world%%%%%";
|
||||
assert_eq!(s.is_empty(), false);
|
||||
assert!(!s.is_empty());
|
||||
for (idx, c) in s.char_indices() {
|
||||
assert_eq!(s.at(idx), Some(c));
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ fn test_format_string_str() {
|
|||
assert_eq!(s.take_literal(&mut buffer), "world%%");
|
||||
|
||||
s.advance_by(1); // advancing over one more %
|
||||
assert_eq!(s.is_empty(), true); // remaining content is empty
|
||||
assert!(s.is_empty()); // remaining content is empty
|
||||
}
|
||||
|
||||
#[cfg(feature = "widestring")]
|
||||
|
@ -122,7 +122,7 @@ fn test_format_string_wstr() {
|
|||
assert_eq!(s.take_literal(&mut buffer), "world%%");
|
||||
|
||||
s.advance_by(1); // advancing over one more %
|
||||
assert_eq!(s.is_empty(), true); // remaining content is empty
|
||||
assert!(s.is_empty()); // remaining content is empty
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -852,10 +852,10 @@ mod test_expressions {
|
|||
} else {
|
||||
errors.push(wgettext_fmt!("Argument is not a number: '%ls'", arg));
|
||||
}
|
||||
} else if floating.map_or(false, |x| x.is_nan()) {
|
||||
} else if floating.is_ok_and(|x| x.is_nan()) {
|
||||
// NaN is an error as far as we're concerned.
|
||||
errors.push(wgettext!("Not a number").to_owned());
|
||||
} else if floating.map_or(false, |x| x.is_infinite()) {
|
||||
} else if floating.is_ok_and(|x| x.is_infinite()) {
|
||||
errors.push(wgettext!("Number is infinite").to_owned());
|
||||
} else if integral == Err(Error::Overflow) {
|
||||
errors.push(wgettext_fmt!("Result too large: %ls", arg));
|
||||
|
|
16
src/env/var.rs
vendored
16
src/env/var.rs
vendored
|
@ -102,7 +102,7 @@ bitflags! {
|
|||
pub struct EnvVar {
|
||||
/// The list of values in this variable.
|
||||
/// Arc allows for cheap copying
|
||||
values: Arc<Box<[WString]>>,
|
||||
values: Arc<[WString]>,
|
||||
/// The variable's flags.
|
||||
flags: EnvVarFlags,
|
||||
}
|
||||
|
@ -111,8 +111,8 @@ impl Default for EnvVar {
|
|||
fn default() -> Self {
|
||||
use std::sync::OnceLock;
|
||||
/// A shared read-only empty list.
|
||||
static EMPTY_LIST: OnceLock<Arc<Box<[WString]>>> = OnceLock::new();
|
||||
let empty_list = EMPTY_LIST.get_or_init(|| Arc::new(Box::new([])));
|
||||
static EMPTY_LIST: OnceLock<Arc<[WString]>> = OnceLock::new();
|
||||
let empty_list = EMPTY_LIST.get_or_init(|| Arc::new([]));
|
||||
|
||||
EnvVar {
|
||||
values: Arc::clone(empty_list),
|
||||
|
@ -130,7 +130,7 @@ impl EnvVar {
|
|||
/// Creates a new `EnvVar`.
|
||||
pub fn new_vec(values: Vec<WString>, flags: EnvVarFlags) -> Self {
|
||||
EnvVar {
|
||||
values: Arc::new(values.into_boxed_slice()),
|
||||
values: values.into(),
|
||||
flags,
|
||||
}
|
||||
}
|
||||
|
@ -199,15 +199,15 @@ impl EnvVar {
|
|||
}
|
||||
|
||||
/// Returns a copy of the variable with new values.
|
||||
pub fn setting_vals(&mut self, values: Vec<WString>) -> Self {
|
||||
pub fn setting_vals(&self, values: Vec<WString>) -> Self {
|
||||
EnvVar {
|
||||
values: Arc::new(values.into_boxed_slice()),
|
||||
values: values.into(),
|
||||
flags: self.flags,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a copy of the variable with the export flag changed.
|
||||
pub fn setting_exports(&mut self, export: bool) -> Self {
|
||||
pub fn setting_exports(&self, export: bool) -> Self {
|
||||
let mut flags = self.flags;
|
||||
flags.set(EnvVarFlags::EXPORT, export);
|
||||
EnvVar {
|
||||
|
@ -217,7 +217,7 @@ impl EnvVar {
|
|||
}
|
||||
|
||||
/// Returns a copy of the variable with the path variable flag changed.
|
||||
pub fn setting_pathvar(&mut self, pathvar: bool) -> Self {
|
||||
pub fn setting_pathvar(&self, pathvar: bool) -> Self {
|
||||
let mut flags = self.flags;
|
||||
flags.set(EnvVarFlags::PATHVAR, pathvar);
|
||||
EnvVar {
|
||||
|
|
|
@ -602,9 +602,9 @@ impl EnvUniversal {
|
|||
let existing = self.vars.get(key);
|
||||
|
||||
// See if the value has changed.
|
||||
let old_exports = existing.map_or(false, |v| v.exports());
|
||||
let old_exports = existing.is_some_and(|v| v.exports());
|
||||
let export_changed = old_exports != new_entry.exports();
|
||||
let value_changed = existing.map_or(false, |v| v != new_entry);
|
||||
let value_changed = existing.is_some_and(|v| v != new_entry);
|
||||
if export_changed || value_changed {
|
||||
self.export_generation += 1;
|
||||
}
|
||||
|
|
|
@ -371,7 +371,7 @@ pub fn is_signal_observed(sig: libc::c_int) -> bool {
|
|||
// We are in a signal handler!
|
||||
OBSERVED_SIGNALS
|
||||
.get(usize::try_from(sig).unwrap())
|
||||
.map_or(false, |s| s.load(Ordering::Relaxed) > 0)
|
||||
.is_some_and(|s| s.load(Ordering::Relaxed) > 0)
|
||||
}
|
||||
|
||||
pub fn get_desc(parser: &Parser, evt: &Event) -> WString {
|
||||
|
|
|
@ -93,7 +93,7 @@ impl FunctionSet {
|
|||
// tombstoned.
|
||||
let props = self.get_props(name);
|
||||
let has_explicit_func =
|
||||
props.map_or(false, |p: Arc<FunctionProperties>| !p.is_autoload.load());
|
||||
props.is_some_and(|p: Arc<FunctionProperties>| !p.is_autoload.load());
|
||||
let tombstoned = self.autoload_tombstones.contains(name);
|
||||
!has_explicit_func && !tombstoned
|
||||
}
|
||||
|
|
|
@ -1127,7 +1127,7 @@ impl<'s> Highlighter<'s> {
|
|||
let mut is_valid_path = false;
|
||||
let at_cursor = self
|
||||
.cursor
|
||||
.map_or(false, |c| arg.source_range().contains_inclusive(c));
|
||||
.is_some_and(|c| arg.source_range().contains_inclusive(c));
|
||||
if cmd_is_cd {
|
||||
// Mark this as an error if it's not 'help' and not a valid cd path.
|
||||
let mut param = arg.source(self.buff).to_owned();
|
||||
|
|
|
@ -1871,9 +1871,11 @@ impl<'a> ExecutionContext {
|
|||
// Assign a job group to the given job.
|
||||
fn setup_group(&self, ctx: &OperationContext<'_>, j: &mut Job) {
|
||||
// We can use the parent group if it's compatible and we're not backgrounded.
|
||||
if ctx.job_group.as_ref().map_or(false, |job_group| {
|
||||
job_group.has_job_id() || !j.wants_job_id()
|
||||
}) && !j.is_initially_background()
|
||||
if ctx
|
||||
.job_group
|
||||
.as_ref()
|
||||
.is_some_and(|job_group| job_group.has_job_id() || !j.wants_job_id())
|
||||
&& !j.is_initially_background()
|
||||
{
|
||||
j.group = ctx.job_group.clone();
|
||||
return;
|
||||
|
|
|
@ -244,7 +244,7 @@ fn parse_util_locate_cmdsub(
|
|||
|
||||
if inout_is_quoted
|
||||
.as_ref()
|
||||
.map_or(false, |is_quoted| **is_quoted)
|
||||
.is_some_and(|is_quoted| **is_quoted)
|
||||
&& !input.is_empty()
|
||||
{
|
||||
pos = process_opening_quote(
|
||||
|
|
|
@ -426,7 +426,7 @@ fn equals_ascii_icase(left: &wstr, right: &wstr) -> bool {
|
|||
return false;
|
||||
}
|
||||
for (lc, rc) in left.chars().zip(right.chars()) {
|
||||
if lc.to_ascii_lowercase() != rc.to_ascii_lowercase() {
|
||||
if !lc.eq_ignore_ascii_case(&rc) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue