diff --git a/src/builtins/math.rs b/src/builtins/math.rs index a3861be8a..e09f503ed 100644 --- a/src/builtins/math.rs +++ b/src/builtins/math.rs @@ -49,8 +49,8 @@ fn parse_cmd_opts( if optarg == "max" { opts.scale = 15; } else { - let scale = fish_wcstoi(optarg); - if scale.is_err() || scale.unwrap() < 0 || scale.unwrap() > 15 { + let scale = fish_wcstoi(optarg).unwrap_or(-1); + if scale < 0 || scale > 15 { streams.err.append(wgettext_fmt!( "%ls: %ls: invalid base value\n", cmd, @@ -59,7 +59,7 @@ fn parse_cmd_opts( return Err(STATUS_INVALID_ARGS); } // We know the value is in the range [0, 15] - opts.scale = scale.unwrap() as usize; + opts.scale = scale as usize; } } 'b' => { @@ -69,8 +69,8 @@ fn parse_cmd_opts( } else if optarg == "octal" { opts.base = 8; } else { - let base = fish_wcstoi(optarg); - if base.is_err() || (base.unwrap() != 8 && base.unwrap() != 16) { + let base = fish_wcstoi(optarg).unwrap_or(-1); + if base != 8 && base != 16 { streams.err.append(wgettext_fmt!( "%ls: %ls: invalid base value\n", cmd, @@ -79,7 +79,7 @@ fn parse_cmd_opts( return Err(STATUS_INVALID_ARGS); } // We know the value is 8 or 16. - opts.base = base.unwrap() as usize; + opts.base = base as usize; } } 'h' => { diff --git a/src/builtins/path.rs b/src/builtins/path.rs index 22b565eed..f36182ccd 100644 --- a/src/builtins/path.rs +++ b/src/builtins/path.rs @@ -747,7 +747,7 @@ fn filter_path(opts: &Options, path: &wstr, uid: Option, gid: Option) let mut type_ok = false; if t.contains(TypeFlags::LINK) { let md = lwstat(path); - type_ok = md.is_ok() && md.unwrap().is_symlink(); + type_ok = md.map(|x| x.is_symlink()).unwrap_or(false); } let Ok(md) = wstat(path) else { // Does not exist diff --git a/src/builtins/test.rs b/src/builtins/test.rs index 95231789a..b18fc1d97 100644 --- a/src/builtins/test.rs +++ b/src/builtins/test.rs @@ -425,17 +425,15 @@ mod test_expressions { } // Parse another expression. - let expr = self.parse_unary_expression(idx, end); - if expr.is_none() { + let Some(expr) = self.parse_unary_expression(idx, end) else { self.add_error(idx, sprintf!("Missing argument at index %u", idx + 1)); if !first { // Clean up the dangling combiner, since it never got its right hand expression. combiners.pop(); } break; - } + }; // Go to the end of this expression. - let expr = expr.unwrap(); idx = expr.range().end; subjects.push(expr); first = false; @@ -773,11 +771,10 @@ mod test_expressions { fn parse_number(arg: &wstr, number: &mut Number, errors: &mut Vec) -> bool { let floating = parse_double(arg); let integral: Result = fish_wcstol(arg); - let got_int = integral.is_ok(); - if got_int { + if let Ok(int) = integral { // Here the value is just an integer; ignore the floating point parse because it may be // invalid (e.g. not a representable integer). - *number = Number::new(integral.unwrap(), 0.0); + *number = Number::new(int, 0.0); true } else if floating.is_ok() && integral.unwrap_err() != Error::Overflow @@ -816,10 +813,10 @@ mod test_expressions { } else { errors.push(wgettext_fmt!("Argument is not a number: '%ls'", arg)); } - } else if floating.is_ok() && floating.unwrap().is_nan() { + } else if floating.map_or(false, |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.is_ok() && floating.unwrap().is_infinite() { + } else if floating.map_or(false, |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/builtins/wait.rs b/src/builtins/wait.rs index d535e2596..c2cfe1ca4 100644 --- a/src/builtins/wait.rs +++ b/src/builtins/wait.rs @@ -180,8 +180,8 @@ pub fn wait(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt for item in &argv[optind..argc] { if iswnumeric(item) { // argument is pid - let mpid: Result = fish_wcstoi(item); - if mpid.is_err() || mpid.unwrap() <= 0 { + let mpid: pid_t = fish_wcstoi(item).unwrap_or(-1); + if mpid <= 0 { streams.err.append(wgettext_fmt!( "%ls: '%ls' is not a valid process id\n", cmd, @@ -189,12 +189,11 @@ pub fn wait(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Opt )); continue; } - let pid = mpid.unwrap() as pid_t; - if !find_wait_handles(WaitHandleQuery::Pid(pid), parser, &mut wait_handles) { + if !find_wait_handles(WaitHandleQuery::Pid(mpid), parser, &mut wait_handles) { streams.err.append(wgettext_fmt!( "%ls: Could not find a job with process id '%d'\n", cmd, - pid, + mpid, )); } } else {