From 1cad9898d620149c236692ee76a21ab885c2ddd6 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 30 Nov 2024 17:01:42 +0100 Subject: [PATCH] Refactor some more .unwrap/asserts No use in asserting and then unwrapping, just .expect() --- src/env/environment_impl.rs | 12 ++++++------ src/tokenizer.rs | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index bf6a08cfa..13b0f0cf2 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -344,8 +344,8 @@ impl EnvScopedImpl { } fn try_get_computed(&self, key: &wstr) -> Option { - let ev = ElectricVar::for_name(key); - if ev.is_none() || !ev.unwrap().computed() { + let ev = ElectricVar::for_name(key)?; + if !ev.computed() { return None; } @@ -994,8 +994,8 @@ impl EnvStackImpl { let mut exports = false; if query.has_export_unexport { exports = query.exports; - } else if oldvar.is_some() { - exports = oldvar.unwrap().exports(); + } else if let Some(v) = oldvar { + exports = v.exports(); } // Resolve whether to be a path variable. @@ -1003,8 +1003,8 @@ impl EnvStackImpl { let pathvar; if query.has_pathvar_unpathvar { pathvar = query.pathvar; - } else if oldvar.is_some() { - pathvar = oldvar.unwrap().is_pathvar(); + } else if let Some(v) = oldvar { + pathvar = v.is_pathvar(); } else { pathvar = variable_should_auto_pathvar(key); } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 722f52654..c9f585f52 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -760,8 +760,7 @@ impl<'c> Tokenizer<'c> { 1, ); } else if mode & TOK_MODE_SUBSHELL { - assert!(!paran_offsets.is_empty()); - let offset_of_open_paran = *paran_offsets.last().unwrap(); + let offset_of_open_paran = *paran_offsets.last().expect("paran_offsets is empty"); return self.call_error( TokenizerError::unterminated_subshell, @@ -771,8 +770,7 @@ impl<'c> Tokenizer<'c> { 1, ); } else if mode & TOK_MODE_CURLY_BRACES { - assert!(!brace_offsets.is_empty()); - let offset_of_open_brace = *brace_offsets.last().unwrap(); + let offset_of_open_brace = *brace_offsets.last().expect("brace_offsets is empty"); return self.call_error( TokenizerError::unterminated_brace,