about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2025-04-01 09:17:23 +0200
committerLukas Wirth <lukastw97@gmail.com>2025-04-01 13:18:37 +0200
commit6e8a96ea986e49f9b7dffdc30818fca242d6d618 (patch)
tree39ba03076caff1bb3fe7f10ac98ee457068c3a0f /src
parent6698106f1fc27d705fd156b920861078978523cf (diff)
downloadrust-6e8a96ea986e49f9b7dffdc30818fca242d6d618.tar.gz
rust-6e8a96ea986e49f9b7dffdc30818fca242d6d618.zip
chore: Remove unnecessary `Arc` clones
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/base-db/src/lib.rs30
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs13
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs4
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs22
4 files changed, 16 insertions, 53 deletions
diff --git a/src/tools/rust-analyzer/crates/base-db/src/lib.rs b/src/tools/rust-analyzer/crates/base-db/src/lib.rs
index e6059e9e790..83857cf2dd0 100644
--- a/src/tools/rust-analyzer/crates/base-db/src/lib.rs
+++ b/src/tools/rust-analyzer/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<SourceRoot>,
         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<ast::SourceFile>;
 
     /// Returns the set of errors obtained from parsing the file including validation errors.
-    fn parse_errors(&self, file_id: EditionedFileId) -> Option<Arc<[SyntaxError]>>;
+    #[salsa::transparent]
+    fn parse_errors(&self, file_id: EditionedFileId) -> Option<&[SyntaxError]>;
 
     #[salsa::transparent]
     fn toolchain_channel(&self, krate: Crate) -> Option<ReleaseChannel>;
@@ -318,12 +314,16 @@ fn parse(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Parse<ast::SourceFil
     ast::SourceFile::parse(&text, edition)
 }
 
-fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<Arc<[SyntaxError]>> {
-    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<Box<[SyntaxError]>> {
+        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/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs
index 4ec8c741da5..e1124c9ff25 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs
@@ -1042,19 +1042,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);
         check_diagnostics(
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
index a8d9b67b4ea..e667d484bef 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs
index 632893a0252..0718e5ac646 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs
@@ -861,28 +861,6 @@ fn main() {
         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})
-}
-            "#,
-        );
-        check_with_config(
-            InlayHintsConfig {
-                type_hints: true,
                 closure_style: ClosureStyle::Hide,
                 ..DISABLED_CONFIG
             },