Remove a few uses of unwrap

This commit is contained in:
Fabian Boehm 2024-05-01 12:28:15 +02:00
parent 69fb620073
commit 89b74a6983
5 changed files with 9 additions and 12 deletions

View File

@ -195,7 +195,7 @@ impl BuiltinBind {
fn list(&self, bind_mode: Option<&wstr>, user: bool, parser: &Parser, streams: &mut IoStreams) {
let lst = self.input_mappings.get_names(user);
for binding in lst {
if bind_mode.is_some() && bind_mode.unwrap() != binding.mode {
if bind_mode.is_some_and(|m| m != binding.mode) {
continue;
}

View File

@ -150,16 +150,14 @@ fn parse_cmd_opts(
let pid: i32 = getpid();
e = EventDescription::ProcessExit { pid };
} else {
let pid = fish_wcstoi(woptarg);
if pid.is_err() || pid.unwrap() < 0 {
let Ok(pid @ 0..) = fish_wcstoi(woptarg) else {
streams.err.append(wgettext_fmt!(
"%ls: %ls: invalid process id",
cmd,
woptarg
));
return STATUS_INVALID_ARGS;
}
let pid = pid.unwrap();
};
if opt == 'p' {
e = EventDescription::ProcessExit { pid };
} else {

View File

@ -786,14 +786,14 @@ impl<'args, 'iter> Arguments<'args, 'iter> {
}
// assert!(num_bytes == self.buffer.len());
let (end, want_newline) = match (&self.split_behavior, self.buffer.last().unwrap()) {
let (end, want_newline) = match (&self.split_behavior, self.buffer.last()) {
// remove the newline — consumers do not expect it
(Newline, b'\n') => (num_bytes - 1, true),
(Newline, Some(b'\n')) => (num_bytes - 1, true),
// we are missing a trailing newline!
(Newline, _) => (num_bytes, false),
// consumers do not expect to deal with the null
// "want_newline" is not currently relevant for Null
(Null, b'\0') => (num_bytes - 1, false),
(Null, Some(b'\0')) => (num_bytes - 1, false),
// we are missing a null!
(Null, _) => (num_bytes, false),
(Never, _) => (num_bytes, false),

View File

@ -167,7 +167,7 @@ impl RegexError {
&WString::from(e.error_message())
);
string_error!(streams, "%ls: %ls\n", cmd, pattern);
string_error!(streams, "%ls: %*ls\n", cmd, e.offset().unwrap(), "^");
string_error!(streams, "%ls: %*ls\n", cmd, e.offset().unwrap_or(0), "^");
}
InvalidCaptureGroupName(name) => {
streams.err.append(wgettext_fmt!(

View File

@ -816,9 +816,8 @@ mod test_expressions {
// invalid (e.g. not a representable integer).
*number = Number::new(int, 0.0);
true
} else if floating.is_ok()
&& integral.unwrap_err() != Error::Overflow
&& floating.unwrap().is_finite()
} else if floating.is_ok_and(|f| f.is_finite())
&& integral.is_err_and(|i| i != Error::Overflow)
{
// Here we parsed an (in range) floating point value that could not be parsed as an integer.
// Break the floating point value into base and delta. Ensure that base is <= the floating