Unnamed repository; edit this file 'description' to name the repository.
refactor: Remove unnecessary `Arc`
Lukas Wirth 2025-03-16
parent 7edfeb9 · commit b5eedad
-rw-r--r--crates/base-db/src/input.rs7
-rw-r--r--crates/hir-def/src/expander.rs7
-rw-r--r--crates/hir-def/src/expr_store/lower.rs4
-rw-r--r--crates/hir-def/src/nameres/assoc.rs4
-rw-r--r--crates/hir-def/src/nameres/tests/incremental.rs2
-rw-r--r--crates/hir-ty/src/display.rs2
-rw-r--r--crates/hir/src/lib.rs4
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/project-model/src/workspace.rs10
-rw-r--r--crates/query-group-macro/tests/logger_db.rs2
-rw-r--r--crates/test-fixture/src/lib.rs4
11 files changed, 22 insertions, 26 deletions
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs
index 3d94060823..2fe4f688f5 100644
--- a/crates/base-db/src/input.rs
+++ b/crates/base-db/src/input.rs
@@ -89,7 +89,7 @@ impl ops::Index<CrateBuilderId> for CrateGraphBuilder {
pub struct CrateBuilder {
pub basic: CrateDataBuilder,
pub extra: ExtraCrateData,
- pub cfg_options: Arc<CfgOptions>,
+ pub cfg_options: CfgOptions,
pub env: Env,
ws_data: Arc<CrateWorkspaceData>,
}
@@ -403,9 +403,8 @@ pub struct Crate {
// This is in `Arc` because it is shared for all crates in a workspace.
#[return_ref]
pub workspace_data: Arc<CrateWorkspaceData>,
- // FIXME: Remove this `Arc`.
#[return_ref]
- pub cfg_options: Arc<CfgOptions>,
+ pub cfg_options: CfgOptions,
#[return_ref]
pub env: Env,
}
@@ -421,7 +420,7 @@ impl CrateGraphBuilder {
edition: Edition,
display_name: Option<CrateDisplayName>,
version: Option<String>,
- cfg_options: Arc<CfgOptions>,
+ cfg_options: CfgOptions,
potential_cfg_options: Option<CfgOptions>,
mut env: Env,
origin: CrateOrigin,
diff --git a/crates/hir-def/src/expander.rs b/crates/hir-def/src/expander.rs
index 895b827967..16cf969b88 100644
--- a/crates/hir-def/src/expander.rs
+++ b/crates/hir-def/src/expander.rs
@@ -11,7 +11,6 @@ use hir_expand::{
};
use span::{Edition, SyntaxContext};
use syntax::{Parse, ast};
-use triomphe::Arc;
use crate::type_ref::{TypesMap, TypesSourceMap};
use crate::{
@@ -21,7 +20,6 @@ use crate::{
#[derive(Debug)]
pub struct Expander {
- cfg_options: Arc<CfgOptions>,
span_map: OnceCell<SpanMap>,
current_file_id: HirFileId,
pub(crate) module: ModuleId,
@@ -44,7 +42,6 @@ impl Expander {
module,
recursion_depth: 0,
recursion_limit,
- cfg_options: Arc::clone(module.krate.cfg_options(db)),
span_map: OnceCell::new(),
}
}
@@ -141,8 +138,8 @@ impl Expander {
)
}
- pub(crate) fn cfg_options(&self) -> &CfgOptions {
- &self.cfg_options
+ pub(crate) fn cfg_options<'db>(&self, db: &'db dyn DefDatabase) -> &'db CfgOptions {
+ self.module.krate.cfg_options(db)
}
pub fn current_file_id(&self) -> HirFileId {
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index fe1a5e8f29..86f31dcaf0 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -1894,14 +1894,14 @@ impl ExprCollector<'_> {
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> {
match self.expander.parse_attrs(self.db, owner).cfg() {
Some(cfg) => {
- if self.expander.cfg_options().check(&cfg) != Some(false) {
+ if self.expander.cfg_options(self.db).check(&cfg) != Some(false) {
return Some(());
}
self.source_map.diagnostics.push(ExpressionStoreDiagnostics::InactiveCode {
node: self.expander.in_file(SyntaxNodePtr::new(owner.syntax())),
cfg,
- opts: self.expander.cfg_options().clone(),
+ opts: self.expander.cfg_options(self.db).clone(),
});
None
diff --git a/crates/hir-def/src/nameres/assoc.rs b/crates/hir-def/src/nameres/assoc.rs
index 1b3d10f098..eb7f8b0061 100644
--- a/crates/hir-def/src/nameres/assoc.rs
+++ b/crates/hir-def/src/nameres/assoc.rs
@@ -167,13 +167,13 @@ impl<'a> AssocItemCollector<'a> {
'items: for &item in assoc_items {
let attrs = item_tree.attrs(self.db, self.module_id.krate, ModItem::from(item).into());
- if !attrs.is_cfg_enabled(self.expander.cfg_options()) {
+ if !attrs.is_cfg_enabled(self.expander.cfg_options(self.db)) {
self.diagnostics.push(DefDiagnostic::unconfigured_code(
self.module_id.local_id,
tree_id,
ModItem::from(item).into(),
attrs.cfg().unwrap(),
- self.expander.cfg_options().clone(),
+ self.expander.cfg_options(self.db).clone(),
));
continue;
}
diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs
index bd25d0bd58..14653c64a6 100644
--- a/crates/hir-def/src/nameres/tests/incremental.rs
+++ b/crates/hir-def/src/nameres/tests/incremental.rs
@@ -58,7 +58,7 @@ pub const BAZ: u32 = 0;
Edition::CURRENT,
Some(CrateDisplayName::from_canonical_name(crate_name)),
None,
- Arc::default(),
+ Default::default(),
None,
Env::default(),
CrateOrigin::Local { repo: None, name: Some(Symbol::intern(crate_name)) },
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index b2e13ba692..0e3c5b9b47 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -1226,7 +1226,7 @@ impl HirDisplay for Ty {
TyKind::Adt(AdtId(def_id), parameters) => {
f.start_location_link((*def_id).into());
match f.display_kind {
- DisplayKind::Diagnostics { .. } | DisplayKind::Test { .. } => {
+ DisplayKind::Diagnostics | DisplayKind::Test => {
let name = match *def_id {
hir_def::AdtId::StructId(it) => db.struct_data(it).name.clone(),
hir_def::AdtId::UnionId(it) => db.union_data(it).name.clone(),
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index b3bb4a0a33..c3834b3c4d 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -276,8 +276,8 @@ impl Crate {
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
}
- pub fn cfg(&self, db: &dyn HirDatabase) -> Arc<CfgOptions> {
- Arc::clone(self.id.cfg_options(db))
+ pub fn cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
+ self.id.cfg_options(db)
}
pub fn potential_cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index f8eb676bfc..f85a7bf2f2 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -250,7 +250,7 @@ impl Analysis {
Edition::CURRENT,
None,
None,
- Arc::new(cfg_options),
+ cfg_options,
None,
Env::default(),
CrateOrigin::Local { repo: None, name: None },
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index f7bb875e65..95148bb1d0 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -1051,7 +1051,7 @@ fn project_json_to_crate_graph(
*edition,
display_name.clone(),
version.clone(),
- Arc::new(cfg_options),
+ cfg_options,
None,
env,
if let Some(name) = display_name.clone() {
@@ -1341,7 +1341,7 @@ fn detached_file_to_crate_graph(
}
cfg_options.insert_atom(sym::rust_analyzer.clone());
override_cfg.apply(&mut cfg_options, "");
- let cfg_options = Arc::new(cfg_options);
+ let cfg_options = cfg_options;
let file_id = match load(detached_file) {
Some(file_id) => file_id,
@@ -1526,7 +1526,7 @@ fn add_target_crate_root(
edition,
Some(CrateDisplayName::from_canonical_name(cargo_name)),
Some(pkg.version.to_string()),
- Arc::new(cfg_options),
+ cfg_options,
potential_cfg_options,
env,
origin,
@@ -1680,13 +1680,13 @@ fn sysroot_to_crate_graph(
extend_crate_graph_with_sysroot(crate_graph, sysroot_cg, sysroot_pm)
}
RustLibSrcWorkspace::Stitched(stitched) => {
- let cfg_options = Arc::new({
+ let cfg_options = {
let mut cfg_options = CfgOptions::default();
cfg_options.extend(rustc_cfg);
cfg_options.insert_atom(sym::debug_assertions.clone());
cfg_options.insert_atom(sym::miri.clone());
cfg_options
- });
+ };
let sysroot_crates: FxHashMap<
crate::sysroot::stitched::RustLibSrcCrate,
CrateBuilderId,
diff --git a/crates/query-group-macro/tests/logger_db.rs b/crates/query-group-macro/tests/logger_db.rs
index b3457c1046..5cf9be36f7 100644
--- a/crates/query-group-macro/tests/logger_db.rs
+++ b/crates/query-group-macro/tests/logger_db.rs
@@ -18,7 +18,7 @@ impl salsa::Database for LoggerDb {
let event = event();
match event.kind {
salsa::EventKind::WillExecute { .. }
- | salsa::EventKind::WillCheckCancellation { .. }
+ | salsa::EventKind::WillCheckCancellation
| salsa::EventKind::DidValidateMemoizedValue { .. }
| salsa::EventKind::WillDiscardStaleOutput { .. }
| salsa::EventKind::DidDiscard { .. } => {
diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs
index 2c5c1c2e7f..3fea49d1f6 100644
--- a/crates/test-fixture/src/lib.rs
+++ b/crates/test-fixture/src/lib.rs
@@ -207,7 +207,7 @@ impl ChangeFixture {
meta.edition,
Some(crate_name.clone().into()),
version,
- From::from(meta.cfg.clone()),
+ meta.cfg.clone(),
Some(meta.cfg),
meta.env,
origin,
@@ -247,7 +247,7 @@ impl ChangeFixture {
Edition::CURRENT,
Some(CrateName::new("ra_test_fixture").unwrap().into()),
None,
- From::from(default_cfg.clone()),
+ default_cfg.clone(),
Some(default_cfg),
default_env,
CrateOrigin::Local { repo: None, name: None },