fix: new clippy warnings from rust 1.85.0 (#15203)

# Description
Mainly some cleanup of `map_or`.
This commit is contained in:
zc he 2025-02-27 21:11:47 +08:00 committed by GitHub
parent 12b8b4580c
commit 96af27fb4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 21 additions and 26 deletions

View File

@ -159,14 +159,11 @@ impl DirInfo {
fn add_file(mut self, f: impl Into<PathBuf>, params: &DirBuilder) -> Self {
let f = f.into();
let include = params
.exclude
.as_ref()
.map_or(true, |x| !x.matches_path(&f));
let include = params.exclude.as_ref().is_none_or(|x| !x.matches_path(&f));
if include {
match FileInfo::new(f, params.deref, self.tag, self.long) {
Ok(file) => {
let inc = params.min.map_or(true, |s| file.size >= s);
let inc = params.min.is_none_or(|s| file.size >= s);
if inc {
self.size += file.size;
self.blocks += file.blocks.unwrap_or(0);

View File

@ -238,7 +238,7 @@ impl View for TryView {
}
fn show_data(&mut self, i: usize) -> bool {
self.table.as_mut().map_or(false, |v| v.show_data(i))
self.table.as_mut().is_some_and(|v| v.show_data(i))
}
}

View File

@ -457,7 +457,7 @@ where
.error(ErrorCode::LoneLeadingSurrogateInHexEscape));
}
let n = (((n1 - 0xD800) as u32) << 10 | (n2 - 0xDC00) as u32)
let n = ((((n1 - 0xD800) as u32) << 10) | (n2 - 0xDC00) as u32)
+ 0x1_0000;
match char::from_u32(n) {

View File

@ -142,25 +142,23 @@ where
fn serialize_f32(self, value: f32) -> Result<()> {
self.formatter.start_value(&mut self.writer)?;
fmt_f32_or_null(&mut self.writer, if value == -0f32 { 0f32 } else { value })
.map_err(From::from)
}
#[inline]
fn serialize_f64(self, value: f64) -> Result<()> {
self.formatter.start_value(&mut self.writer)?;
fmt_f64_or_null(&mut self.writer, if value == -0f64 { 0f64 } else { value })
.map_err(From::from)
}
#[inline]
fn serialize_char(self, value: char) -> Result<()> {
self.formatter.start_value(&mut self.writer)?;
escape_char(&mut self.writer, value).map_err(From::from)
escape_char(&mut self.writer, value)
}
#[inline]
fn serialize_str(self, value: &str) -> Result<()> {
quote_str(&mut self.writer, &mut self.formatter, value).map_err(From::from)
quote_str(&mut self.writer, &mut self.formatter, value)
}
#[inline]
@ -496,7 +494,7 @@ where
#[inline]
fn serialize_str(self, value: &str) -> Result<()> {
escape_key(&mut self.ser.writer, value).map_err(From::from)
escape_key(&mut self.ser.writer, value)
}
type SerializeSeq = ser::Impossible<(), Error>;
@ -853,7 +851,7 @@ pub fn escape_key<W>(wr: &mut W, value: &str) -> Result<()>
where
W: io::Write,
{
escape_bytes(wr, value.as_bytes()).map_err(From::from)
escape_bytes(wr, value.as_bytes())
}
#[inline]

View File

@ -57,7 +57,7 @@ fn try_find_id_in_def(
) -> Option<(Id, Span)> {
let mut span = None;
for arg in call.arguments.iter() {
if location.map_or(true, |pos| arg.span().contains(*pos)) {
if location.is_none_or(|pos| arg.span().contains(*pos)) {
// String means this argument is the name
if let Argument::Positional(expr) = arg {
if let Expr::String(_) = &expr.expr {
@ -76,7 +76,7 @@ fn try_find_id_in_def(
let name = working_set.get_span_contents(span);
let decl_id = Id::Declaration(working_set.find_decl(name)?);
id_ref
.map_or(true, |id_r| decl_id == *id_r)
.is_none_or(|id_r| decl_id == *id_r)
.then_some((decl_id, span))
}
@ -96,7 +96,7 @@ fn try_find_id_in_mod(
location: Option<&usize>,
id_ref: Option<&Id>,
) -> Option<(Id, Span)> {
let check_location = |span: &Span| location.map_or(true, |pos| span.contains(*pos));
let check_location = |span: &Span| location.is_none_or(|pos| span.contains(*pos));
call.arguments.first().and_then(|arg| {
if !check_location(&arg.span()) {
@ -109,7 +109,7 @@ fn try_find_id_in_mod(
let found_id = Id::Module(module_id);
let found_span = strip_quotes(arg.span(), working_set);
id_ref
.map_or(true, |id_r| found_id == *id_r)
.is_none_or(|id_r| found_id == *id_r)
.then_some((found_id, found_span))
}
_ => None,
@ -152,7 +152,7 @@ fn try_find_id_in_use(
.or(working_set.find_variable(name).map(Id::Variable)),
_ => None,
};
let check_location = |span: &Span| location.map_or(true, |pos| span.contains(*pos));
let check_location = |span: &Span| location.is_none_or(|pos| span.contains(*pos));
// Get module id if required
let module_name = call.arguments.first()?;
@ -232,10 +232,10 @@ fn try_find_id_in_overlay(
location: Option<&usize>,
id: Option<&Id>,
) -> Option<(Id, Span)> {
let check_location = |span: &Span| location.map_or(true, |pos| span.contains(*pos));
let check_location = |span: &Span| location.is_none_or(|pos| span.contains(*pos));
let module_from_overlay_name = |name: &str, span: Span| {
let found_id = Id::Module(working_set.find_overlay(name.as_bytes())?.origin);
id.map_or(true, |id_r| found_id == *id_r)
id.is_none_or(|id_r| found_id == *id_r)
.then_some((found_id, strip_quotes(span, working_set)))
};
for arg in call.arguments.iter() {
@ -272,7 +272,7 @@ fn get_matched_module_id(
let path = std::path::PathBuf::from(name.as_ref());
let stem = path.file_stem().and_then(|fs| fs.to_str()).unwrap_or(&name);
let found_id = Id::Module(working_set.find_module(stem.as_bytes())?);
id.map_or(true, |id_r| found_id == *id_r)
id.is_none_or(|id_r| found_id == *id_r)
.then_some((found_id, span))
}

View File

@ -2817,7 +2817,7 @@ pub const DURATION_UNIT_GROUPS: &[UnitGroup] = &[
fn modf(x: f64) -> (f64, f64) {
let rv2: f64;
let mut u = x.to_bits();
let e = ((u >> 52 & 0x7ff) as i32) - 0x3ff;
let e = (((u >> 52) & 0x7ff) as i32) - 0x3ff;
/* no fractional part */
if e >= 52 {

View File

@ -247,7 +247,7 @@ pub(crate) fn setup_config(
&config_file, &env_file, is_login_shell
);
let create_scaffold = nu_path::nu_config_dir().map_or(false, |p| !p.exists());
let create_scaffold = nu_path::nu_config_dir().is_some_and(|p| !p.exists());
let result = catch_unwind(AssertUnwindSafe(|| {
#[cfg(feature = "plugin")]

View File

@ -24,7 +24,7 @@ pub(crate) fn run_commands(
trace!("run_commands");
let start_time = std::time::Instant::now();
let create_scaffold = nu_path::nu_config_dir().map_or(false, |p| !p.exists());
let create_scaffold = nu_path::nu_config_dir().is_some_and(|p| !p.exists());
// if the --no-config-file(-n) option is NOT passed, load the plugin file,
// load the default env file or custom (depending on parsed_nu_cli_args.env_file),
@ -54,7 +54,7 @@ pub(crate) fn run_commands(
perf!("read env.nu", start_time, use_color);
let start_time = std::time::Instant::now();
let create_scaffold = nu_path::nu_config_dir().map_or(false, |p| !p.exists());
let create_scaffold = nu_path::nu_config_dir().is_some_and(|p| !p.exists());
// If we have a config file parameter *OR* we have a login shell parameter, read the config file
if parsed_nu_cli_args.config_file.is_some() || parsed_nu_cli_args.login_shell.is_some() {
@ -122,7 +122,7 @@ pub(crate) fn run_file(
// if the --no-config-file(-n) flag is passed, do not load plugin, env, or config files
if parsed_nu_cli_args.no_config_file.is_none() {
let start_time = std::time::Instant::now();
let create_scaffold = nu_path::nu_config_dir().map_or(false, |p| !p.exists());
let create_scaffold = nu_path::nu_config_dir().is_some_and(|p| !p.exists());
#[cfg(feature = "plugin")]
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file);
perf!("read plugins", start_time, use_color);