From 5c2bd816aea19b6346948c02a47534860e30cd22 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Mar 2024 00:29:29 -0500 Subject: [PATCH] Fix Clippy warnings in `settings` crate (#8700) This PR fixes a number of Clippy warnings in the `settings` crate. Release Notes: - N/A --- crates/settings/src/settings_file.rs | 6 ++--- crates/settings/src/settings_store.rs | 34 +++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/settings/src/settings_file.rs b/crates/settings/src/settings_file.rs index b0cc8ade5c..9106bbfb0a 100644 --- a/crates/settings/src/settings_file.rs +++ b/crates/settings/src/settings_file.rs @@ -6,7 +6,7 @@ use gpui::{AppContext, BackgroundExecutor}; use std::{io::ErrorKind, path::PathBuf, sync::Arc, time::Duration}; use util::{paths, ResultExt}; -pub const EMPTY_THEME_NAME: &'static str = "empty-theme"; +pub const EMPTY_THEME_NAME: &str = "empty-theme"; #[cfg(any(test, feature = "test-support"))] pub fn test_settings() -> String { @@ -52,7 +52,7 @@ pub fn watch_config_file( } if let Ok(contents) = fs.load(&path).await { - if !tx.unbounded_send(contents).is_ok() { + if tx.unbounded_send(contents).is_err() { break; } } @@ -100,7 +100,7 @@ async fn load_settings(fs: &Arc) -> Result { return Ok(crate::initial_user_settings_content().to_string()); } } - return Err(err); + Err(err) } } } diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index 116dc1520f..2cde1187ab 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -96,7 +96,7 @@ pub trait Settings: 'static + Send + Sync { } #[track_caller] - fn get_global<'a>(cx: &'a AppContext) -> &'a Self + fn get_global(cx: &AppContext) -> &Self where Self: Sized, { @@ -104,7 +104,7 @@ pub trait Settings: 'static + Send + Sync { } #[track_caller] - fn try_read_global<'a, R>(cx: &'a AsyncAppContext, f: impl FnOnce(&Self) -> R) -> Option + fn try_read_global(cx: &AsyncAppContext, f: impl FnOnce(&Self) -> R) -> Option where Self: Sized, { @@ -112,7 +112,7 @@ pub trait Settings: 'static + Send + Sync { } #[track_caller] - fn override_global<'a>(settings: Self, cx: &'a mut AppContext) + fn override_global(settings: Self, cx: &mut AppContext) where Self: Sized, { @@ -210,10 +210,10 @@ impl SettingsStore { if let Some(release_settings) = &self .raw_user_settings - .get(&*release_channel::RELEASE_CHANNEL.dev_name()) + .get(release_channel::RELEASE_CHANNEL.dev_name()) { if let Some(release_settings) = setting_value - .deserialize_setting(&release_settings) + .deserialize_setting(release_settings) .log_err() { user_values_stack.push(release_settings); @@ -316,7 +316,7 @@ impl SettingsStore { let raw_settings = parse_json_with_comments::(text).unwrap_or_default(); let old_content = match setting.deserialize_setting(&raw_settings) { Ok(content) => content.0.downcast::().unwrap(), - Err(_) => Box::new(T::FileContent::default()), + Err(_) => Box::<::FileContent>::default(), }; let mut new_content = old_content.clone(); update(&mut new_content); @@ -340,7 +340,7 @@ impl SettingsStore { &new_value, &mut edits, ); - return edits; + edits } /// Configure the tab sized when updating JSON files. @@ -543,10 +543,10 @@ impl SettingsStore { if let Some(release_settings) = &self .raw_user_settings - .get(&*release_channel::RELEASE_CHANNEL.dev_name()) + .get(release_channel::RELEASE_CHANNEL.dev_name()) { if let Some(release_settings) = setting_value - .deserialize_setting(&release_settings) + .deserialize_setting(release_settings) .log_err() { user_settings_stack.push(release_settings); @@ -662,7 +662,7 @@ impl AnySettingValue for SettingValue { fn value_for_path(&self, path: Option<(usize, &Path)>) -> &dyn Any { if let Some((root_id, path)) = path { for (settings_root_id, settings_path, value) in self.local_values.iter().rev() { - if root_id == *settings_root_id && path.starts_with(&settings_path) { + if root_id == *settings_root_id && path.starts_with(settings_path) { return value; } } @@ -755,8 +755,8 @@ fn replace_value_in_json_text( tab_size: usize, new_value: &serde_json::Value, ) -> (Range, String) { - const LANGUAGE_OVERRIDES: &'static str = "language_overrides"; - const LANGUAGES: &'static str = "languages"; + const LANGUAGE_OVERRIDES: &str = "language_overrides"; + const LANGUAGES: &str = "languages"; lazy_static! { static ref PAIR_QUERY: tree_sitter::Query = tree_sitter::Query::new( @@ -799,15 +799,15 @@ fn replace_value_in_json_text( break; } - first_key_start.get_or_insert_with(|| key_range.start); + first_key_start.get_or_insert(key_range.start); let found_key = text .get(key_range.clone()) .map(|key_text| { if key_path[depth] == LANGUAGES && has_language_overrides { - return key_text == format!("\"{}\"", LANGUAGE_OVERRIDES); + key_text == format!("\"{}\"", LANGUAGE_OVERRIDES) } else { - return key_text == format!("\"{}\"", key_path[depth]); + key_text == format!("\"{}\"", key_path[depth]) } }) .unwrap_or(false); @@ -820,9 +820,9 @@ fn replace_value_in_json_text( if depth == key_path.len() { break; - } else { - first_key_start = None; } + + first_key_start = None; } }