From 75c005a4d4a51de33f705851da71b61cf8fad4a9 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Wed, 3 Dec 2025 00:14:14 +0100 Subject: [PATCH] lint: convert is_some+unwrap into if let This fixes an `unnecessary_unwrap` lint shown by nightly Clippy. Closes #12130 --- src/bin/fish.rs | 12 +++++++----- src/history/history.rs | 6 +++--- src/reader/reader.rs | 35 +++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/bin/fish.rs b/src/bin/fish.rs index 0ba044145..c6414de12 100644 --- a/src/bin/fish.rs +++ b/src/bin/fish.rs @@ -515,12 +515,14 @@ fn throwing_main() -> i32 { parser.set_last_statuses(Statuses::just(STATUS_CMD_OK)); // TODO: if-let-chains - if opts.profile_startup_output.is_some() && opts.profile_startup_output != opts.profile_output { - parser.emit_profiling(&opts.profile_startup_output.unwrap()); + if let Some(path) = &opts.profile_startup_output { + if opts.profile_startup_output != opts.profile_output { + parser.emit_profiling(path); - // If we are profiling both, ensure the startup data only - // ends up in the startup file. - parser.clear_profiling(); + // If we are profiling both, ensure the startup data only + // ends up in the startup file. + parser.clear_profiling(); + } } PROFILING_ACTIVE.store(opts.profile_output.is_some()); diff --git a/src/history/history.rs b/src/history/history.rs index 0bce64329..2be22727e 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -415,9 +415,9 @@ fn timestamp_now(&self) -> SystemTime { /// Loads old items if necessary. /// Return a reference to the loaded history file. fn load_old_if_needed(&mut self) -> &HistoryFile { - if self.file_contents.is_some() { - return self.file_contents.as_ref().unwrap(); - }; + if let Some(ref file_contents) = self.file_contents { + return file_contents; + } let Ok(Some(history_path)) = self.history_file_path() else { return self.file_contents.insert(HistoryFile::create_empty()); }; diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 0d4b8b74e..0c821b311 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -1800,23 +1800,26 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) { let mut colors = data.colors.clone(); // Highlight any history search. - if !self.conf.in_silent_mode && data.history_search_range.is_some() { - let mut range = data.history_search_range.unwrap().as_usize(); - if range.end > colors.len() { - range.start = range.start.min(colors.len()); - range.end = colors.len(); - } - - let explicit_foreground = self - .vars() - .get_unless_empty(L!("fish_color_search_match")) - .is_some_and(|var| parse_text_face(var.as_list()).fg.is_some()); - - for color in &mut colors[range] { - if explicit_foreground { - color.foreground = HighlightRole::search_match; + if let Some(range) = data.history_search_range { + // TODO(MSRV>=1.88): let chain + if !self.conf.in_silent_mode { + let mut range = range.as_usize(); + if range.end > colors.len() { + range.start = range.start.min(colors.len()); + range.end = colors.len(); + } + + let explicit_foreground = self + .vars() + .get_unless_empty(L!("fish_color_search_match")) + .is_some_and(|var| parse_text_face(var.as_list()).fg.is_some()); + + for color in &mut colors[range] { + if explicit_foreground { + color.foreground = HighlightRole::search_match; + } + color.background = HighlightRole::search_match; } - color.background = HighlightRole::search_match; } }