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) { fn list(&self, bind_mode: Option<&wstr>, user: bool, parser: &Parser, streams: &mut IoStreams) {
let lst = self.input_mappings.get_names(user); let lst = self.input_mappings.get_names(user);
for binding in lst { 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; continue;
} }

View File

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

View File

@ -786,14 +786,14 @@ impl<'args, 'iter> Arguments<'args, 'iter> {
} }
// assert!(num_bytes == self.buffer.len()); // 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 // 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! // we are missing a trailing newline!
(Newline, _) => (num_bytes, false), (Newline, _) => (num_bytes, false),
// consumers do not expect to deal with the null // consumers do not expect to deal with the null
// "want_newline" is not currently relevant for 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! // we are missing a null!
(Null, _) => (num_bytes, false), (Null, _) => (num_bytes, false),
(Never, _) => (num_bytes, false), (Never, _) => (num_bytes, false),

View File

@ -167,7 +167,7 @@ impl RegexError {
&WString::from(e.error_message()) &WString::from(e.error_message())
); );
string_error!(streams, "%ls: %ls\n", cmd, pattern); 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) => { InvalidCaptureGroupName(name) => {
streams.err.append(wgettext_fmt!( streams.err.append(wgettext_fmt!(

View File

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