diff --git a/printf/src/tests.rs b/printf/src/tests.rs index e87e41b96..fb7446651 100644 --- a/printf/src/tests.rs +++ b/printf/src/tests.rs @@ -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] diff --git a/src/builtins/test.rs b/src/builtins/test.rs index 7dfeabce7..31102253b 100644 --- a/src/builtins/test.rs +++ b/src/builtins/test.rs @@ -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)); diff --git a/src/env/var.rs b/src/env/var.rs index 9e8f10e62..62ec9920e 100644 --- a/src/env/var.rs +++ b/src/env/var.rs @@ -102,7 +102,7 @@ bitflags! { pub struct EnvVar { /// The list of values in this variable. /// Arc allows for cheap copying - values: Arc>, + 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>> = OnceLock::new(); - let empty_list = EMPTY_LIST.get_or_init(|| Arc::new(Box::new([]))); + static EMPTY_LIST: OnceLock> = 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, 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) -> Self { + pub fn setting_vals(&self, values: Vec) -> 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 { diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index ab343a9ab..e6e76a067 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -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; } diff --git a/src/event.rs b/src/event.rs index 75303a09e..9d40e47f2 100644 --- a/src/event.rs +++ b/src/event.rs @@ -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 { diff --git a/src/function.rs b/src/function.rs index 584022bab..5dada6658 100644 --- a/src/function.rs +++ b/src/function.rs @@ -93,7 +93,7 @@ impl FunctionSet { // tombstoned. let props = self.get_props(name); let has_explicit_func = - props.map_or(false, |p: Arc| !p.is_autoload.load()); + props.is_some_and(|p: Arc| !p.is_autoload.load()); let tombstoned = self.autoload_tombstones.contains(name); !has_explicit_func && !tombstoned } diff --git a/src/highlight.rs b/src/highlight.rs index 1f1186459..7a439081c 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -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(); diff --git a/src/parse_execution.rs b/src/parse_execution.rs index 35b7595dc..54cd83f92 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -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; diff --git a/src/parse_util.rs b/src/parse_util.rs index 4fec58f31..60f98f948 100644 --- a/src/parse_util.rs +++ b/src/parse_util.rs @@ -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( diff --git a/src/signal.rs b/src/signal.rs index cf3af5184..79766c183 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -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; } }