Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #19494 from Veykril/push-uzmzppouxuvr
chore: Remove unnecessary `Arc` clones
Lukas Wirth 2025-04-01
parent f1551a9 · parent 1c7f253 · commit c7845a6
-rw-r--r--crates/base-db/src/lib.rs30
-rw-r--r--crates/ide-diagnostics/src/handlers/type_mismatch.rs13
-rw-r--r--crates/ide-diagnostics/src/lib.rs4
-rw-r--r--crates/ide/src/inlay_hints/bind_pat.rs22
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<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/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
@@ -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/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
@@ -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
},