From 1c7f253ec9f7d741a074a431f90d3285c8ed2b38 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 1 Apr 2025 09:17:23 +0200 Subject: [PATCH] chore: Remove unnecessary `Arc` clones --- crates/base-db/src/lib.rs | 30 +++++++++---------- .../src/handlers/type_mismatch.rs | 13 -------- crates/ide-diagnostics/src/lib.rs | 4 +-- crates/ide/src/inlay_hints/bind_pat.rs | 22 -------------- 4 files changed, 16 insertions(+), 53 deletions(-) diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index e6059e9e79..83857cf2dd 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -64,8 +64,7 @@ impl Files { } pub fn set_file_text(&self, db: &mut dyn SourceDatabase, file_id: vfs::FileId, text: &str) { - let files = Arc::clone(&self.files); - match files.entry(file_id) { + match self.files.entry(file_id) { Entry::Occupied(mut occupied) => { occupied.get_mut().set_text(db).to(Arc::from(text)); } @@ -83,8 +82,7 @@ impl Files { text: &str, durability: Durability, ) { - let files = Arc::clone(&self.files); - match files.entry(file_id) { + match self.files.entry(file_id) { Entry::Occupied(mut occupied) => { occupied.get_mut().set_text(db).with_durability(durability).to(Arc::from(text)); } @@ -113,8 +111,7 @@ impl Files { source_root: Arc, durability: Durability, ) { - let source_roots = Arc::clone(&self.source_roots); - match source_roots.entry(source_root_id) { + match self.source_roots.entry(source_root_id) { Entry::Occupied(mut occupied) => { occupied.get_mut().set_source_root(db).with_durability(durability).to(source_root); } @@ -141,9 +138,7 @@ impl Files { source_root_id: SourceRootId, durability: Durability, ) { - let file_source_roots = Arc::clone(&self.file_source_roots); - // let db = self; - match file_source_roots.entry(id) { + match self.file_source_roots.entry(id) { Entry::Occupied(mut occupied) => { occupied .get_mut() @@ -203,7 +198,8 @@ pub trait RootQueryDb: SourceDatabase + salsa::Database { fn parse(&self, file_id: EditionedFileId) -> Parse; /// Returns the set of errors obtained from parsing the file including validation errors. - fn parse_errors(&self, file_id: EditionedFileId) -> Option>; + #[salsa::transparent] + fn parse_errors(&self, file_id: EditionedFileId) -> Option<&[SyntaxError]>; #[salsa::transparent] fn toolchain_channel(&self, krate: Crate) -> Option; @@ -318,12 +314,16 @@ fn parse(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Parse Option> { - let errors = db.parse(file_id).errors(); - match &*errors { - [] => None, - [..] => Some(errors.into()), +fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<&[SyntaxError]> { + #[salsa::tracked(return_ref)] + fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option> { + let errors = db.parse(file_id).errors(); + match &*errors { + [] => None, + [..] => Some(errors.into()), + } } + parse_errors(db, file_id).as_ref().map(|it| &**it) } fn source_root_crates(db: &dyn RootQueryDb, id: SourceRootId) -> Arc<[Crate]> { diff --git a/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/crates/ide-diagnostics/src/handlers/type_mismatch.rs index 4ec8c741da..e1124c9ff2 100644 --- a/crates/ide-diagnostics/src/handlers/type_mismatch.rs +++ b/crates/ide-diagnostics/src/handlers/type_mismatch.rs @@ -1041,19 +1041,6 @@ fn test() -> String { ); } - #[test] - fn closure_mismatch_show_different_type() { - check_diagnostics( - r#" -fn f() { - let mut x = (|| 1, 2); - x = (|| 3, 4); - //^^^^ error: expected {closure#23552}, found {closure#23553} -} - "#, - ); - } - #[test] fn type_mismatch_range_adjustment() { cov_mark::check!(type_mismatch_range_adjustment); diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs index a8d9b67b4e..e667d484be 100644 --- a/crates/ide-diagnostics/src/lib.rs +++ b/crates/ide-diagnostics/src/lib.rs @@ -332,7 +332,6 @@ pub fn syntax_diagnostics( // [#3434] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily. db.parse_errors(editioned_file_id_wrapper) - .as_deref() .into_iter() .flatten() .take(128) @@ -409,8 +408,7 @@ pub fn semantic_diagnostics( // A bunch of parse errors in a file indicate some bigger structural parse changes in the // file, so we skip semantic diagnostics so we can show these faster. Some(m) => { - if db.parse_errors(editioned_file_id_wrapper).as_deref().is_none_or(|es| es.len() < 16) - { + if db.parse_errors(editioned_file_id_wrapper).is_none_or(|es| es.len() < 16) { m.diagnostics(db, &mut diags, config.style_lints); } } diff --git a/crates/ide/src/inlay_hints/bind_pat.rs b/crates/ide/src/inlay_hints/bind_pat.rs index 632893a025..0718e5ac64 100644 --- a/crates/ide/src/inlay_hints/bind_pat.rs +++ b/crates/ide/src/inlay_hints/bind_pat.rs @@ -855,28 +855,6 @@ fn main() { //^ |i32| -> () let p = (y, z); //^ (|i32| -> i32, |i32| -> ()) -} - "#, - ); - check_with_config( - InlayHintsConfig { - type_hints: true, - closure_style: ClosureStyle::ClosureWithId, - ..DISABLED_CONFIG - }, - r#" -//- minicore: fn -fn main() { - let x = || 2; - //^ {closure#25600} - let y = |t: i32| x() + t; - //^ {closure#25601} - let mut t = 5; - //^ i32 - let z = |k: i32| { t += k; }; - //^ {closure#25602} - let p = (y, z); - //^ ({closure#25601}, {closure#25602}) } "#, );