From 233b28a1b9ae6bfc681f39a202092220d4c0af08 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Sun, 1 Jan 2023 23:50:45 -0500 Subject: [PATCH] Appease clippy --- crates/gpui/build.rs | 4 ++-- crates/gpui/src/platform/mac/platform.rs | 2 +- crates/gpui_macros/src/gpui_macros.rs | 8 +++----- crates/live_kit_client/build.rs | 10 +++++----- crates/media/build.rs | 2 +- crates/media/src/media.rs | 6 +++--- crates/rpc/src/auth.rs | 2 +- crates/snippet/src/snippet.rs | 2 +- crates/sqlez/src/connection.rs | 6 +++--- crates/sqlez/src/statement.rs | 8 ++++---- crates/sqlez/src/thread_safe_connection.rs | 13 ++++++------- crates/sqlez/src/typed_statements.rs | 12 ++++++------ crates/sqlez_macros/src/sqlez_macros.rs | 6 +++--- crates/sum_tree/src/tree_map.rs | 2 +- crates/util/src/channel.rs | 2 +- crates/util/src/lib.rs | 2 +- crates/zed/src/languages/ruby.rs | 4 ++-- crates/zed/src/main.rs | 4 ++-- crates/zed/src/zed.rs | 6 +++--- 19 files changed, 49 insertions(+), 52 deletions(-) diff --git a/crates/gpui/build.rs b/crates/gpui/build.rs index 3fb0119782..23f6f04992 100644 --- a/crates/gpui/build.rs +++ b/crates/gpui/build.rs @@ -52,7 +52,7 @@ fn compile_metal_shaders() { println!("cargo:rerun-if-changed={}", shader_path); let output = Command::new("xcrun") - .args(&[ + .args([ "-sdk", "macosx", "metal", @@ -76,7 +76,7 @@ fn compile_metal_shaders() { } let output = Command::new("xcrun") - .args(&["-sdk", "macosx", "metallib"]) + .args(["-sdk", "macosx", "metallib"]) .arg(air_output_path) .arg("-o") .arg(metallib_output_path) diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index f703d863be..3e2ef73634 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -647,7 +647,7 @@ impl platform::Platform for MacPlatform { attrs.set(kSecReturnAttributes as *const _, cf_true); attrs.set(kSecReturnData as *const _, cf_true); - let mut result = CFTypeRef::from(ptr::null_mut()); + let mut result = CFTypeRef::from(ptr::null()); let status = SecItemCopyMatching(attrs.as_concrete_TypeRef(), &mut result); match status { security::errSecSuccess => {} diff --git a/crates/gpui_macros/src/gpui_macros.rs b/crates/gpui_macros/src/gpui_macros.rs index e28d1711d2..cabae1ac0a 100644 --- a/crates/gpui_macros/src/gpui_macros.rs +++ b/crates/gpui_macros/src/gpui_macros.rs @@ -162,11 +162,9 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream { if let FnArg::Typed(arg) = arg { if let Type::Path(ty) = &*arg.ty { let last_segment = ty.path.segments.last(); - match last_segment.map(|s| s.ident.to_string()).as_deref() { - Some("StdRng") => { - inner_fn_args.extend(quote!(rand::SeedableRng::seed_from_u64(seed),)); - } - _ => {} + + if let Some("StdRng") = last_segment.map(|s| s.ident.to_string()).as_deref() { + inner_fn_args.extend(quote!(rand::SeedableRng::seed_from_u64(seed),)); } } else { inner_fn_args.extend(quote!(cx,)); diff --git a/crates/live_kit_client/build.rs b/crates/live_kit_client/build.rs index bceb4fb927..bcd3f76dca 100644 --- a/crates/live_kit_client/build.rs +++ b/crates/live_kit_client/build.rs @@ -5,7 +5,7 @@ use std::{ process::Command, }; -const SWIFT_PACKAGE_NAME: &'static str = "LiveKitBridge"; +const SWIFT_PACKAGE_NAME: &str = "LiveKitBridge"; #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] @@ -61,8 +61,8 @@ fn build_bridge(swift_target: &SwiftTarget) { let swift_package_root = swift_package_root(); if !Command::new("swift") .arg("build") - .args(&["--configuration", &env::var("PROFILE").unwrap()]) - .args(&["--triple", &swift_target.target.triple]) + .args(["--configuration", &env::var("PROFILE").unwrap()]) + .args(["--triple", &swift_target.target.triple]) .current_dir(&swift_package_root) .status() .unwrap() @@ -116,7 +116,7 @@ fn get_swift_target() -> SwiftTarget { let target = format!("{}-apple-macosx{}", arch, MACOS_TARGET_VERSION); let swift_target_info_str = Command::new("swift") - .args(&["-target", &target, "-print-target-info"]) + .args(["-target", &target, "-print-target-info"]) .output() .unwrap() .stdout; @@ -143,7 +143,7 @@ fn copy_dir(source: &Path, destination: &Path) { assert!( Command::new("cp") .arg("-R") - .args(&[source, destination]) + .args([source, destination]) .status() .unwrap() .success(), diff --git a/crates/media/build.rs b/crates/media/build.rs index 1ee8f23e41..7e66efd39d 100644 --- a/crates/media/build.rs +++ b/crates/media/build.rs @@ -3,7 +3,7 @@ use std::{env, path::PathBuf, process::Command}; fn main() { let sdk_path = String::from_utf8( Command::new("xcrun") - .args(&["--sdk", "macosx", "--show-sdk-path"]) + .args(["--sdk", "macosx", "--show-sdk-path"]) .output() .unwrap() .stdout, diff --git a/crates/media/src/media.rs b/crates/media/src/media.rs index fe69e684e7..1c76e6befb 100644 --- a/crates/media/src/media.rs +++ b/crates/media/src/media.rs @@ -113,9 +113,9 @@ pub mod core_video { let mut this = ptr::null(); let result = CVMetalTextureCacheCreate( kCFAllocatorDefault, - ptr::null_mut(), + ptr::null(), metal_device, - ptr::null_mut(), + ptr::null(), &mut this, ); if result == kCVReturnSuccess { @@ -192,7 +192,7 @@ pub mod core_video { pub fn as_texture_ref(&self) -> &metal::TextureRef { unsafe { let texture = CVMetalTextureGetTexture(self.as_concrete_TypeRef()); - &metal::TextureRef::from_ptr(texture as *mut _) + metal::TextureRef::from_ptr(texture as *mut _) } } } diff --git a/crates/rpc/src/auth.rs b/crates/rpc/src/auth.rs index 5254ef9ca4..39c8c39a44 100644 --- a/crates/rpc/src/auth.rs +++ b/crates/rpc/src/auth.rs @@ -23,7 +23,7 @@ pub fn random_token() -> String { for byte in token_bytes.iter_mut() { *byte = rng.gen(); } - base64::encode_config(&token_bytes, base64::URL_SAFE) + base64::encode_config(token_bytes, base64::URL_SAFE) } impl PublicKey { diff --git a/crates/snippet/src/snippet.rs b/crates/snippet/src/snippet.rs index 808701569a..2957f415da 100644 --- a/crates/snippet/src/snippet.rs +++ b/crates/snippet/src/snippet.rs @@ -62,7 +62,7 @@ fn parse_snippet<'a>( } } Some(_) => { - let chunk_end = source.find(&['}', '$', '\\']).unwrap_or(source.len()); + let chunk_end = source.find(['}', '$', '\\']).unwrap_or(source.len()); let (chunk, rest) = source.split_at(chunk_end); text.push_str(chunk); source = rest; diff --git a/crates/sqlez/src/connection.rs b/crates/sqlez/src/connection.rs index 3342845d14..3c6cb31196 100644 --- a/crates/sqlez/src/connection.rs +++ b/crates/sqlez/src/connection.rs @@ -20,7 +20,7 @@ unsafe impl Send for Connection {} impl Connection { pub(crate) fn open(uri: &str, persistent: bool) -> Result { let mut connection = Self { - sqlite3: 0 as *mut _, + sqlite3: ptr::null_mut(), persistent, write: RefCell::new(true), _sqlite: PhantomData, @@ -32,7 +32,7 @@ impl Connection { CString::new(uri)?.as_ptr(), &mut connection.sqlite3, flags, - 0 as *const _, + ptr::null(), ); // Turn on extended error codes @@ -97,7 +97,7 @@ impl Connection { let remaining_sql_str = remaining_sql.to_str().unwrap().trim(); remaining_sql_str != ";" && !remaining_sql_str.is_empty() } { - let mut raw_statement = 0 as *mut sqlite3_stmt; + let mut raw_statement = ptr::null_mut::(); let mut remaining_sql_ptr = ptr::null(); sqlite3_prepare_v2( self.sqlite3, diff --git a/crates/sqlez/src/statement.rs b/crates/sqlez/src/statement.rs index 86035f5d0a..f3ec6d4854 100644 --- a/crates/sqlez/src/statement.rs +++ b/crates/sqlez/src/statement.rs @@ -48,7 +48,7 @@ impl<'a> Statement<'a> { .trim(); remaining_sql_str != ";" && !remaining_sql_str.is_empty() } { - let mut raw_statement = 0 as *mut sqlite3_stmt; + let mut raw_statement = ptr::null_mut::(); let mut remaining_sql_ptr = ptr::null(); sqlite3_prepare_v2( connection.sqlite3, @@ -101,7 +101,7 @@ impl<'a> Statement<'a> { } } - fn bind_index_with(&self, index: i32, bind: impl Fn(&*mut sqlite3_stmt) -> ()) -> Result<()> { + fn bind_index_with(&self, index: i32, bind: impl Fn(&*mut sqlite3_stmt)) -> Result<()> { let mut any_succeed = false; unsafe { for raw_statement in self.raw_statements.iter() { @@ -133,7 +133,7 @@ impl<'a> Statement<'a> { }) } - pub fn column_blob<'b>(&'b mut self, index: i32) -> Result<&'b [u8]> { + pub fn column_blob(&mut self, index: i32) -> Result<&[u8]> { let index = index as c_int; let pointer = unsafe { sqlite3_column_blob(self.current_statement(), index) }; @@ -217,7 +217,7 @@ impl<'a> Statement<'a> { }) } - pub fn column_text<'b>(&'b mut self, index: i32) -> Result<&'b str> { + pub fn column_text(&mut self, index: i32) -> Result<&str> { let index = index as c_int; let pointer = unsafe { sqlite3_column_text(self.current_statement(), index) }; diff --git a/crates/sqlez/src/thread_safe_connection.rs b/crates/sqlez/src/thread_safe_connection.rs index 2c51b776ed..c3fe4657ee 100644 --- a/crates/sqlez/src/thread_safe_connection.rs +++ b/crates/sqlez/src/thread_safe_connection.rs @@ -114,12 +114,12 @@ impl ThreadSafeConnection { let mut queues = QUEUES.write(); if !queues.contains_key(&self.uri) { let mut write_queue_constructor = - write_queue_constructor.unwrap_or(background_thread_queue()); + write_queue_constructor.unwrap_or_else(background_thread_queue); queues.insert(self.uri.clone(), write_queue_constructor()); return true; } } - return false; + false } pub fn builder(uri: &str, persistent: bool) -> ThreadSafeConnectionBuilder { @@ -187,10 +187,9 @@ impl ThreadSafeConnection { *connection.write.get_mut() = false; if let Some(initialize_query) = connection_initialize_query { - connection.exec(initialize_query).expect(&format!( - "Initialize query failed to execute: {}", - initialize_query - ))() + connection.exec(initialize_query).unwrap_or_else(|_| { + panic!("Initialize query failed to execute: {}", initialize_query) + })() .unwrap() } @@ -225,7 +224,7 @@ impl Clone for ThreadSafeConnection { Self { uri: self.uri.clone(), persistent: self.persistent, - connection_initialize_query: self.connection_initialize_query.clone(), + connection_initialize_query: self.connection_initialize_query, connections: self.connections.clone(), _migrator: PhantomData, } diff --git a/crates/sqlez/src/typed_statements.rs b/crates/sqlez/src/typed_statements.rs index c7d8b20aa5..df4a2987b5 100644 --- a/crates/sqlez/src/typed_statements.rs +++ b/crates/sqlez/src/typed_statements.rs @@ -8,7 +8,7 @@ use crate::{ impl Connection { pub fn exec<'a>(&'a self, query: &str) -> Result Result<()>> { - let mut statement = Statement::prepare(&self, query)?; + let mut statement = Statement::prepare(self, query)?; Ok(move || statement.exec()) } @@ -16,7 +16,7 @@ impl Connection { &'a self, query: &str, ) -> Result Result<()>> { - let mut statement = Statement::prepare(&self, query)?; + let mut statement = Statement::prepare(self, query)?; Ok(move |bindings| statement.with_bindings(bindings)?.exec()) } @@ -24,7 +24,7 @@ impl Connection { &'a self, query: &str, ) -> Result Result>> { - let mut statement = Statement::prepare(&self, query)?; + let mut statement = Statement::prepare(self, query)?; Ok(move || statement.rows::()) } @@ -32,7 +32,7 @@ impl Connection { &'a self, query: &str, ) -> Result Result>> { - let mut statement = Statement::prepare(&self, query)?; + let mut statement = Statement::prepare(self, query)?; Ok(move |bindings| statement.with_bindings(bindings)?.rows::()) } @@ -40,7 +40,7 @@ impl Connection { &'a self, query: &str, ) -> Result Result>> { - let mut statement = Statement::prepare(&self, query)?; + let mut statement = Statement::prepare(self, query)?; Ok(move || statement.maybe_row::()) } @@ -48,7 +48,7 @@ impl Connection { &'a self, query: &str, ) -> Result Result>> { - let mut statement = Statement::prepare(&self, query)?; + let mut statement = Statement::prepare(self, query)?; Ok(move |bindings| { statement .with_bindings(bindings) diff --git a/crates/sqlez_macros/src/sqlez_macros.rs b/crates/sqlez_macros/src/sqlez_macros.rs index 429f45db7e..675576c997 100644 --- a/crates/sqlez_macros/src/sqlez_macros.rs +++ b/crates/sqlez_macros/src/sqlez_macros.rs @@ -33,14 +33,14 @@ fn create_error( .skip_while(|(offset, _)| offset <= &error_offset) .map(|(_, span)| span) .next() - .unwrap_or(Span::call_site()); + .unwrap_or_else(Span::call_site); let error_text = format!("Sql Error: {}\nFor Query: {}", error, formatted_sql); TokenStream::from(Error::new(error_span.into(), error_text).into_compile_error()) } fn make_sql(tokens: TokenStream) -> (Vec<(usize, Span)>, String) { let mut sql_tokens = vec![]; - flatten_stream(tokens.clone(), &mut sql_tokens); + flatten_stream(tokens, &mut sql_tokens); // Lookup of spans by offset at the end of the token let mut spans: Vec<(usize, Span)> = Vec::new(); let mut sql = String::new(); @@ -67,7 +67,7 @@ fn flatten_stream(tokens: TokenStream, result: &mut Vec<(String, Span)>) { result.push((close_delimiter(group.delimiter()), group.span())); } TokenTree::Ident(ident) => { - result.push((format!("{} ", ident.to_string()), ident.span())); + result.push((format!("{} ", ident), ident.span())); } leaf_tree => result.push((leaf_tree.to_string(), leaf_tree.span())), } diff --git a/crates/sum_tree/src/tree_map.rs b/crates/sum_tree/src/tree_map.rs index 8672ca398f..112366cdf5 100644 --- a/crates/sum_tree/src/tree_map.rs +++ b/crates/sum_tree/src/tree_map.rs @@ -58,7 +58,7 @@ impl TreeMap { self.0.insert_or_replace(MapEntry { key, value }, &()); } - pub fn remove<'a>(&mut self, key: &'a K) -> Option { + pub fn remove(&mut self, key: &K) -> Option { let mut removed = None; let mut cursor = self.0.cursor::>(); let key = MapKeyRef(Some(key)); diff --git a/crates/util/src/channel.rs b/crates/util/src/channel.rs index 3edf26dc95..03b0f04271 100644 --- a/crates/util/src/channel.rs +++ b/crates/util/src/channel.rs @@ -4,7 +4,7 @@ use lazy_static::lazy_static; lazy_static! { pub static ref RELEASE_CHANNEL_NAME: String = env::var("ZED_RELEASE_CHANNEL") - .unwrap_or(include_str!("../../zed/RELEASE_CHANNEL").to_string()); + .unwrap_or_else(|_| include_str!("../../zed/RELEASE_CHANNEL").to_string()); pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME.as_str() { "dev" => ReleaseChannel::Dev, "preview" => ReleaseChannel::Preview, diff --git a/crates/util/src/lib.rs b/crates/util/src/lib.rs index d9015ca6c0..e79cc269c9 100644 --- a/crates/util/src/lib.rs +++ b/crates/util/src/lib.rs @@ -36,7 +36,7 @@ pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String { debug_assert!(max_chars >= 5); if s.len() > max_chars { - format!("{}…", truncate(&s, max_chars.saturating_sub(3))) + format!("{}…", truncate(s, max_chars.saturating_sub(3))) } else { s.to_string() } diff --git a/crates/zed/src/languages/ruby.rs b/crates/zed/src/languages/ruby.rs index 6aad293d34..cbfb5e35a7 100644 --- a/crates/zed/src/languages/ruby.rs +++ b/crates/zed/src/languages/ruby.rs @@ -50,14 +50,14 @@ impl LspAdapter for RubyLanguageServer { grammar.highlight_id_for_name("type")? } lsp::CompletionItemKind::KEYWORD => { - if label.starts_with(":") { + if label.starts_with(':') { grammar.highlight_id_for_name("string.special.symbol")? } else { grammar.highlight_id_for_name("keyword")? } } lsp::CompletionItemKind::VARIABLE => { - if label.starts_with("@") { + if label.starts_with('@') { grammar.highlight_id_for_name("property")? } else { return None; diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 5ac7cb36b6..f4fa919c48 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -101,7 +101,7 @@ fn main() { //Setup settings global before binding actions cx.set_global(SettingsFile::new( - &*paths::SETTINGS, + &paths::SETTINGS, settings_file_content.clone(), fs.clone(), )); @@ -586,7 +586,7 @@ async fn handle_cli_connection( responses .send(CliResponse::Exit { - status: if errored { 1 } else { 0 }, + status: i32::from(errored), }) .log_err(); } diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index e6d50f43af..c3af91306d 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -338,11 +338,11 @@ pub fn initialize_workspace( }, "schemas": [ { - "fileMatch": [schema_file_match(&*paths::SETTINGS)], + "fileMatch": [schema_file_match(&paths::SETTINGS)], "schema": settings_file_json_schema(theme_names, language_names), }, { - "fileMatch": [schema_file_match(&*paths::KEYMAP)], + "fileMatch": [schema_file_match(&paths::KEYMAP)], "schema": keymap_file_json_schema(&action_names), } ] @@ -646,7 +646,7 @@ fn open_bundled_config_file( cx: &mut ViewContext, ) { workspace - .with_local_workspace(&app_state.clone(), cx, |workspace, cx| { + .with_local_workspace(&app_state, cx, |workspace, cx| { let project = workspace.project().clone(); let buffer = project.update(cx, |project, cx| { let text = Assets::get(asset_path).unwrap().data;