mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-14 03:02:52 +08:00
Remove some .unwrap()
This commit is contained in:
parent
5d55dd9879
commit
79320e3ba7
2
src/env/environment.rs
vendored
2
src/env/environment.rs
vendored
|
@ -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.
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
8
src/env/environment_impl.rs
vendored
8
src/env/environment_impl.rs
vendored
|
@ -769,8 +769,8 @@ impl EnvStackImpl {
|
|||
// This is distinct from the unspecified scope,
|
||||
// which is the global scope if no function exists.
|
||||
let mut node = self.base.locals.clone();
|
||||
while node.next().is_some() {
|
||||
node = node.next().unwrap();
|
||||
while let Some(next_node) = node.next() {
|
||||
node = next_node;
|
||||
// The first node that introduces a new scope is ours.
|
||||
// If this doesn't happen, we go on until we've reached the
|
||||
// topmost local scope.
|
||||
|
@ -837,8 +837,8 @@ impl EnvStackImpl {
|
|||
result.status = remove_from_chain(&mut self.base.locals, key);
|
||||
} else if query.function {
|
||||
let mut node = self.base.locals.clone();
|
||||
while node.next().is_some() {
|
||||
node = node.next().unwrap();
|
||||
while let Some(next_node) = node.next() {
|
||||
node = next_node;
|
||||
if node.borrow().new_scope {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -157,8 +157,8 @@ fn guess_emoji_width(vars: &EnvStack) {
|
|||
|
||||
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.
|
||||
let new_width = fish_wcstoi(&width_str.as_string()).unwrap_or(1).clamp(1, 2);
|
||||
FISH_EMOJI_WIDTH.store(isize::try_from(new_width).unwrap(), Ordering::Relaxed);
|
||||
let new_width = fish_wcstoi(&width_str.as_string()).unwrap_or(1).clamp(1, 2) as isize;
|
||||
FISH_EMOJI_WIDTH.store(new_width, Ordering::Relaxed);
|
||||
FLOG!(
|
||||
term_support,
|
||||
"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())
|
||||
.unwrap_or(1)
|
||||
// Clamp in case of negative values.
|
||||
.max(0);
|
||||
crate::fallback::FISH_AMBIGUOUS_WIDTH
|
||||
.store(isize::try_from(new_width).unwrap(), Ordering::Relaxed);
|
||||
.max(0) as isize;
|
||||
crate::fallback::FISH_AMBIGUOUS_WIDTH.store(new_width, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
fn handle_term_size_change(vars: &EnvStack) {
|
||||
|
|
|
@ -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();
|
||||
if !f.skip_out() {
|
||||
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");
|
||||
}
|
||||
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 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");
|
||||
}
|
||||
if status.is_success() {
|
||||
|
|
|
@ -990,7 +990,7 @@ impl InputMappingSet {
|
|||
} else {
|
||||
&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));
|
||||
}
|
||||
|
||||
|
|
|
@ -335,7 +335,6 @@ fn test_no_dots() {
|
|||
// DirIter does not return . or .. by default.
|
||||
let dir = DirIter::new(L!(".")).expect("Should be able to open CWD");
|
||||
for entry in dir {
|
||||
assert!(entry.is_ok());
|
||||
let entry = entry.unwrap();
|
||||
assert_ne!(entry.name, ".");
|
||||
assert_ne!(entry.name, "..");
|
||||
|
@ -350,7 +349,6 @@ fn test_dots() {
|
|||
let mut seen_dot = false;
|
||||
let mut seen_dotdot = false;
|
||||
for entry in dir {
|
||||
assert!(entry.is_ok());
|
||||
let entry = entry.unwrap();
|
||||
if entry.name == "." {
|
||||
seen_dot = true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user