From b5eca5f2fcdf34e1a8090be1d3d3c829b95e84c3 Mon Sep 17 00:00:00 2001 From: Johann Hemmann Date: Fri, 19 Jan 2024 13:22:32 +0100 Subject: [PATCH] collapsible_if --- Cargo.toml | 1 - crates/hir-ty/src/mir/eval.rs | 8 ++-- crates/hir-ty/src/mir/lower.rs | 9 +++-- .../src/handlers/generate_getter_or_setter.rs | 6 +-- crates/rust-analyzer/src/lsp/to_proto.rs | 28 +++++++------- crates/rust-analyzer/src/main_loop.rs | 8 ++-- crates/rust-analyzer/src/reload.rs | 38 +++++++++---------- 7 files changed, 47 insertions(+), 51 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2819016b0..7ec85629cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -169,7 +169,6 @@ new_ret_no_self = "allow" ## Following lints should be tackled at some point borrowed_box = "allow" borrow_deref_ref = "allow" -collapsible_if = "allow" collapsible_match = "allow" clone_on_copy = "allow" derivable_impls = "allow" diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index f8e4c6e43d..124adf8864 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -1842,10 +1842,10 @@ impl Evaluator<'_> { } } let layout = self.layout(ty); - if self.assert_placeholder_ty_is_unused { - if matches!(layout, Err(MirEvalError::LayoutError(LayoutError::HasPlaceholder, _))) { - return Ok(Some((0, 1))); - } + if self.assert_placeholder_ty_is_unused + && matches!(layout, Err(MirEvalError::LayoutError(LayoutError::HasPlaceholder, _))) + { + return Ok(Some((0, 1))); } let layout = layout?; Ok(layout diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 169e0e204c..d320dcdad2 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -948,10 +948,11 @@ impl<'ctx> MirLowerCtx<'ctx> { // for binary operator, and use without adjust to simplify our conditions. let lhs_ty = self.expr_ty_without_adjust(*lhs); let rhs_ty = self.expr_ty_without_adjust(*rhs); - if matches!(op, BinaryOp::CmpOp(syntax::ast::CmpOp::Eq { .. })) { - if lhs_ty.as_raw_ptr().is_some() && rhs_ty.as_raw_ptr().is_some() { - break 'b true; - } + if matches!(op, BinaryOp::CmpOp(syntax::ast::CmpOp::Eq { .. })) + && lhs_ty.as_raw_ptr().is_some() + && rhs_ty.as_raw_ptr().is_some() + { + break 'b true; } let builtin_inequal_impls = matches!( op, diff --git a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs index 596e277e0f..79307fcec5 100644 --- a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs +++ b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs @@ -377,10 +377,8 @@ fn build_source_change( }; // Insert `$0` only for last getter we generate - if i == record_fields_count - 1 { - if ctx.config.snippet_cap.is_some() { - getter_buf = getter_buf.replacen("fn ", "fn $0", 1); - } + if i == record_fields_count - 1 && ctx.config.snippet_cap.is_some() { + getter_buf = getter_buf.replacen("fn ", "fn $0", 1); } // For first element we do not merge with '\n', as diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index d26fe16cbd..fe381fbeb3 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -310,22 +310,20 @@ fn completion_item( set_score(&mut lsp_item, max_relevance, item.relevance); - if config.completion().enable_imports_on_the_fly { - if !item.import_to_add.is_empty() { - let imports: Vec<_> = item - .import_to_add - .into_iter() - .filter_map(|(import_path, import_name)| { - Some(lsp_ext::CompletionImport { - full_import_path: import_path, - imported_name: import_name, - }) + if config.completion().enable_imports_on_the_fly && !item.import_to_add.is_empty() { + let imports: Vec<_> = item + .import_to_add + .into_iter() + .filter_map(|(import_path, import_name)| { + Some(lsp_ext::CompletionImport { + full_import_path: import_path, + imported_name: import_name, }) - .collect(); - if !imports.is_empty() { - let data = lsp_ext::CompletionResolveData { position: tdpp.clone(), imports }; - lsp_item.data = Some(to_value(data).unwrap()); - } + }) + .collect(); + if !imports.is_empty() { + let data = lsp_ext::CompletionResolveData { position: tdpp.clone(), imports }; + lsp_item.data = Some(to_value(data).unwrap()); } } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index f767585697..0173805d44 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -579,10 +579,10 @@ impl GlobalState { let path = VfsPath::from(path); // if the file is in mem docs, it's managed by the client via notifications // so only set it if its not in there - if !self.mem_docs.contains(&path) { - if is_changed || vfs.file_id(&path).is_none() { - vfs.set_file_contents(path, contents); - } + if !self.mem_docs.contains(&path) + && (is_changed || vfs.file_id(&path).is_none()) + { + vfs.set_file_contents(path, contents); } } } diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 83736c65ed..b64936e799 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -454,27 +454,27 @@ impl GlobalState { let files_config = self.config.files(); let project_folders = ProjectFolders::new(&self.workspaces, &files_config.exclude); - if self.proc_macro_clients.is_empty() || !same_workspaces { - if self.config.expand_proc_macros() { - tracing::info!("Spawning proc-macro servers"); + if (self.proc_macro_clients.is_empty() || !same_workspaces) + && self.config.expand_proc_macros() + { + tracing::info!("Spawning proc-macro servers"); - self.proc_macro_clients = Arc::from_iter(self.workspaces.iter().map(|ws| { - let path = match self.config.proc_macro_srv() { - Some(path) => path, - None => ws.find_sysroot_proc_macro_srv()?, - }; + self.proc_macro_clients = Arc::from_iter(self.workspaces.iter().map(|ws| { + let path = match self.config.proc_macro_srv() { + Some(path) => path, + None => ws.find_sysroot_proc_macro_srv()?, + }; - tracing::info!("Using proc-macro server at {path}"); - ProcMacroServer::spawn(path.clone()).map_err(|err| { - tracing::error!( - "Failed to run proc-macro server from path {path}, error: {err:?}", - ); - anyhow::format_err!( - "Failed to run proc-macro server from path {path}, error: {err:?}", - ) - }) - })) - }; + tracing::info!("Using proc-macro server at {path}"); + ProcMacroServer::spawn(path.clone()).map_err(|err| { + tracing::error!( + "Failed to run proc-macro server from path {path}, error: {err:?}", + ); + anyhow::format_err!( + "Failed to run proc-macro server from path {path}, error: {err:?}", + ) + }) + })) } let watch = match files_config.watcher {