Remove some .unwrap()

This commit is contained in:
Fabian Boehm 2025-01-18 09:40:59 +01:00
parent 5d55dd9879
commit 79320e3ba7
6 changed files with 12 additions and 15 deletions

View File

@ -805,7 +805,7 @@ pub fn env_init(paths: Option<&ConfigPaths>, do_uvars: bool, default_paths: bool
// Look for a global exported variable with the same name. // Look for a global exported variable with the same name.
let global = EnvStack::globals().getf(name, EnvMode::GLOBAL | EnvMode::EXPORT); let global = EnvStack::globals().getf(name, EnvMode::GLOBAL | EnvMode::EXPORT);
if global.is_some() && global.unwrap().as_string() == uvar.as_string() { if global.is_some_and(|x| x.as_string() == uvar.as_string()) {
to_skip.push(name.to_owned()); to_skip.push(name.to_owned());
} }
} }

View File

@ -769,8 +769,8 @@ impl EnvStackImpl {
// This is distinct from the unspecified scope, // This is distinct from the unspecified scope,
// which is the global scope if no function exists. // which is the global scope if no function exists.
let mut node = self.base.locals.clone(); let mut node = self.base.locals.clone();
while node.next().is_some() { while let Some(next_node) = node.next() {
node = node.next().unwrap(); node = next_node;
// The first node that introduces a new scope is ours. // The first node that introduces a new scope is ours.
// If this doesn't happen, we go on until we've reached the // If this doesn't happen, we go on until we've reached the
// topmost local scope. // topmost local scope.
@ -837,8 +837,8 @@ impl EnvStackImpl {
result.status = remove_from_chain(&mut self.base.locals, key); result.status = remove_from_chain(&mut self.base.locals, key);
} else if query.function { } else if query.function {
let mut node = self.base.locals.clone(); let mut node = self.base.locals.clone();
while node.next().is_some() { while let Some(next_node) = node.next() {
node = node.next().unwrap(); node = next_node;
if node.borrow().new_scope { if node.borrow().new_scope {
break; break;
} }

View File

@ -157,8 +157,8 @@ fn guess_emoji_width(vars: &EnvStack) {
if let Some(width_str) = vars.get(L!("fish_emoji_width")) { if let Some(width_str) = vars.get(L!("fish_emoji_width")) {
// The only valid values are 1 or 2; we default to 1 if it was an invalid int. // The only valid values are 1 or 2; we default to 1 if it was an invalid int.
let new_width = fish_wcstoi(&width_str.as_string()).unwrap_or(1).clamp(1, 2); let new_width = fish_wcstoi(&width_str.as_string()).unwrap_or(1).clamp(1, 2) as isize;
FISH_EMOJI_WIDTH.store(isize::try_from(new_width).unwrap(), Ordering::Relaxed); FISH_EMOJI_WIDTH.store(new_width, Ordering::Relaxed);
FLOG!( FLOG!(
term_support, term_support,
"Overriding default fish_emoji_width w/", "Overriding default fish_emoji_width w/",
@ -228,9 +228,8 @@ fn handle_change_ambiguous_width(vars: &EnvStack) {
.and_then(|fish_ambiguous_width| fish_wcstoi(&fish_ambiguous_width).ok()) .and_then(|fish_ambiguous_width| fish_wcstoi(&fish_ambiguous_width).ok())
.unwrap_or(1) .unwrap_or(1)
// Clamp in case of negative values. // Clamp in case of negative values.
.max(0); .max(0) as isize;
crate::fallback::FISH_AMBIGUOUS_WIDTH crate::fallback::FISH_AMBIGUOUS_WIDTH.store(new_width, Ordering::Relaxed);
.store(isize::try_from(new_width).unwrap(), Ordering::Relaxed);
} }
fn handle_term_size_change(vars: &EnvStack) { fn handle_term_size_change(vars: &EnvStack) {

View File

@ -604,7 +604,7 @@ fn run_internal_process(p: &Process, outdata: Vec<u8>, errdata: Vec<u8>, ios: &I
let mut status = f.success_status.clone(); let mut status = f.success_status.clone();
if !f.skip_out() { if !f.skip_out() {
if let Err(err) = write_loop(&f.src_outfd, &f.outdata) { if let Err(err) = write_loop(&f.src_outfd, &f.outdata) {
if err.raw_os_error().unwrap() != EPIPE { if err.raw_os_error() != Some(EPIPE) {
perror("write"); perror("write");
} }
if status.is_success() { if status.is_success() {
@ -614,7 +614,7 @@ fn run_internal_process(p: &Process, outdata: Vec<u8>, errdata: Vec<u8>, ios: &I
} }
if !f.skip_err() { if !f.skip_err() {
if let Err(err) = write_loop(&f.src_errfd, &f.errdata) { if let Err(err) = write_loop(&f.src_errfd, &f.errdata) {
if err.raw_os_error().unwrap() != EPIPE { if err.raw_os_error() != Some(EPIPE) {
perror("write"); perror("write");
} }
if status.is_success() { if status.is_success() {

View File

@ -990,7 +990,7 @@ impl InputMappingSet {
} else { } else {
&mut self.preset_mapping_list &mut self.preset_mapping_list
}; };
let should_erase = |m: &InputMapping| mode.is_none() || mode.unwrap() == m.mode; let should_erase = |m: &InputMapping| mode.is_none_or(|x| x == m.mode);
ml.retain(|m| !should_erase(m)); ml.retain(|m| !should_erase(m));
} }

View File

@ -335,7 +335,6 @@ fn test_no_dots() {
// DirIter does not return . or .. by default. // DirIter does not return . or .. by default.
let dir = DirIter::new(L!(".")).expect("Should be able to open CWD"); let dir = DirIter::new(L!(".")).expect("Should be able to open CWD");
for entry in dir { for entry in dir {
assert!(entry.is_ok());
let entry = entry.unwrap(); let entry = entry.unwrap();
assert_ne!(entry.name, "."); assert_ne!(entry.name, ".");
assert_ne!(entry.name, ".."); assert_ne!(entry.name, "..");
@ -350,7 +349,6 @@ fn test_dots() {
let mut seen_dot = false; let mut seen_dot = false;
let mut seen_dotdot = false; let mut seen_dotdot = false;
for entry in dir { for entry in dir {
assert!(entry.is_ok());
let entry = entry.unwrap(); let entry = entry.unwrap();
if entry.name == "." { if entry.name == "." {
seen_dot = true; seen_dot = true;