Skip to content

Commit cd0582c

Browse files
committed
refactor: Remove unnecessary Arc
1 parent ccecb29 commit cd0582c

File tree

11 files changed

+22
-26
lines changed

11 files changed

+22
-26
lines changed

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl ops::Index<CrateBuilderId> for CrateGraphBuilder {
8989
pub struct CrateBuilder {
9090
pub basic: CrateDataBuilder,
9191
pub extra: ExtraCrateData,
92-
pub cfg_options: Arc<CfgOptions>,
92+
pub cfg_options: CfgOptions,
9393
pub env: Env,
9494
ws_data: Arc<CrateWorkspaceData>,
9595
}
@@ -403,9 +403,8 @@ pub struct Crate {
403403
// This is in `Arc` because it is shared for all crates in a workspace.
404404
#[return_ref]
405405
pub workspace_data: Arc<CrateWorkspaceData>,
406-
// FIXME: Remove this `Arc`.
407406
#[return_ref]
408-
pub cfg_options: Arc<CfgOptions>,
407+
pub cfg_options: CfgOptions,
409408
#[return_ref]
410409
pub env: Env,
411410
}
@@ -421,7 +420,7 @@ impl CrateGraphBuilder {
421420
edition: Edition,
422421
display_name: Option<CrateDisplayName>,
423422
version: Option<String>,
424-
cfg_options: Arc<CfgOptions>,
423+
cfg_options: CfgOptions,
425424
potential_cfg_options: Option<CfgOptions>,
426425
mut env: Env,
427426
origin: CrateOrigin,

src/tools/rust-analyzer/crates/hir-def/src/expander.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use hir_expand::{
1111
};
1212
use span::{Edition, SyntaxContext};
1313
use syntax::{Parse, ast};
14-
use triomphe::Arc;
1514

1615
use crate::type_ref::{TypesMap, TypesSourceMap};
1716
use crate::{
@@ -21,7 +20,6 @@ use crate::{
2120

2221
#[derive(Debug)]
2322
pub struct Expander {
24-
cfg_options: Arc<CfgOptions>,
2523
span_map: OnceCell<SpanMap>,
2624
current_file_id: HirFileId,
2725
pub(crate) module: ModuleId,
@@ -44,7 +42,6 @@ impl Expander {
4442
module,
4543
recursion_depth: 0,
4644
recursion_limit,
47-
cfg_options: Arc::clone(module.krate.cfg_options(db)),
4845
span_map: OnceCell::new(),
4946
}
5047
}
@@ -141,8 +138,8 @@ impl Expander {
141138
)
142139
}
143140

144-
pub(crate) fn cfg_options(&self) -> &CfgOptions {
145-
&self.cfg_options
141+
pub(crate) fn cfg_options<'db>(&self, db: &'db dyn DefDatabase) -> &'db CfgOptions {
142+
self.module.krate.cfg_options(db)
146143
}
147144

148145
pub fn current_file_id(&self) -> HirFileId {

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,14 +1894,14 @@ impl ExprCollector<'_> {
18941894
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> {
18951895
match self.expander.parse_attrs(self.db, owner).cfg() {
18961896
Some(cfg) => {
1897-
if self.expander.cfg_options().check(&cfg) != Some(false) {
1897+
if self.expander.cfg_options(self.db).check(&cfg) != Some(false) {
18981898
return Some(());
18991899
}
19001900

19011901
self.source_map.diagnostics.push(ExpressionStoreDiagnostics::InactiveCode {
19021902
node: self.expander.in_file(SyntaxNodePtr::new(owner.syntax())),
19031903
cfg,
1904-
opts: self.expander.cfg_options().clone(),
1904+
opts: self.expander.cfg_options(self.db).clone(),
19051905
});
19061906

19071907
None

src/tools/rust-analyzer/crates/hir-def/src/nameres/assoc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ impl<'a> AssocItemCollector<'a> {
167167

168168
'items: for &item in assoc_items {
169169
let attrs = item_tree.attrs(self.db, self.module_id.krate, ModItem::from(item).into());
170-
if !attrs.is_cfg_enabled(self.expander.cfg_options()) {
170+
if !attrs.is_cfg_enabled(self.expander.cfg_options(self.db)) {
171171
self.diagnostics.push(DefDiagnostic::unconfigured_code(
172172
self.module_id.local_id,
173173
tree_id,
174174
ModItem::from(item).into(),
175175
attrs.cfg().unwrap(),
176-
self.expander.cfg_options().clone(),
176+
self.expander.cfg_options(self.db).clone(),
177177
));
178178
continue;
179179
}

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/incremental.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub const BAZ: u32 = 0;
5858
Edition::CURRENT,
5959
Some(CrateDisplayName::from_canonical_name(crate_name)),
6060
None,
61-
Arc::default(),
61+
Default::default(),
6262
None,
6363
Env::default(),
6464
CrateOrigin::Local { repo: None, name: Some(Symbol::intern(crate_name)) },

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ impl HirDisplay for Ty {
12261226
TyKind::Adt(AdtId(def_id), parameters) => {
12271227
f.start_location_link((*def_id).into());
12281228
match f.display_kind {
1229-
DisplayKind::Diagnostics { .. } | DisplayKind::Test { .. } => {
1229+
DisplayKind::Diagnostics | DisplayKind::Test => {
12301230
let name = match *def_id {
12311231
hir_def::AdtId::StructId(it) => db.struct_data(it).name.clone(),
12321232
hir_def::AdtId::UnionId(it) => db.union_data(it).name.clone(),

src/tools/rust-analyzer/crates/hir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ impl Crate {
276276
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
277277
}
278278

279-
pub fn cfg(&self, db: &dyn HirDatabase) -> Arc<CfgOptions> {
280-
Arc::clone(self.id.cfg_options(db))
279+
pub fn cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
280+
self.id.cfg_options(db)
281281
}
282282

283283
pub fn potential_cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {

src/tools/rust-analyzer/crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl Analysis {
250250
Edition::CURRENT,
251251
None,
252252
None,
253-
Arc::new(cfg_options),
253+
cfg_options,
254254
None,
255255
Env::default(),
256256
CrateOrigin::Local { repo: None, name: None },

src/tools/rust-analyzer/crates/project-model/src/workspace.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ fn project_json_to_crate_graph(
10511051
*edition,
10521052
display_name.clone(),
10531053
version.clone(),
1054-
Arc::new(cfg_options),
1054+
cfg_options,
10551055
None,
10561056
env,
10571057
if let Some(name) = display_name.clone() {
@@ -1341,7 +1341,7 @@ fn detached_file_to_crate_graph(
13411341
}
13421342
cfg_options.insert_atom(sym::rust_analyzer.clone());
13431343
override_cfg.apply(&mut cfg_options, "");
1344-
let cfg_options = Arc::new(cfg_options);
1344+
let cfg_options = cfg_options;
13451345

13461346
let file_id = match load(detached_file) {
13471347
Some(file_id) => file_id,
@@ -1526,7 +1526,7 @@ fn add_target_crate_root(
15261526
edition,
15271527
Some(CrateDisplayName::from_canonical_name(cargo_name)),
15281528
Some(pkg.version.to_string()),
1529-
Arc::new(cfg_options),
1529+
cfg_options,
15301530
potential_cfg_options,
15311531
env,
15321532
origin,
@@ -1680,13 +1680,13 @@ fn sysroot_to_crate_graph(
16801680
extend_crate_graph_with_sysroot(crate_graph, sysroot_cg, sysroot_pm)
16811681
}
16821682
RustLibSrcWorkspace::Stitched(stitched) => {
1683-
let cfg_options = Arc::new({
1683+
let cfg_options = {
16841684
let mut cfg_options = CfgOptions::default();
16851685
cfg_options.extend(rustc_cfg);
16861686
cfg_options.insert_atom(sym::debug_assertions.clone());
16871687
cfg_options.insert_atom(sym::miri.clone());
16881688
cfg_options
1689-
});
1689+
};
16901690
let sysroot_crates: FxHashMap<
16911691
crate::sysroot::stitched::RustLibSrcCrate,
16921692
CrateBuilderId,

src/tools/rust-analyzer/crates/query-group-macro/tests/logger_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl salsa::Database for LoggerDb {
1818
let event = event();
1919
match event.kind {
2020
salsa::EventKind::WillExecute { .. }
21-
| salsa::EventKind::WillCheckCancellation { .. }
21+
| salsa::EventKind::WillCheckCancellation
2222
| salsa::EventKind::DidValidateMemoizedValue { .. }
2323
| salsa::EventKind::WillDiscardStaleOutput { .. }
2424
| salsa::EventKind::DidDiscard { .. } => {

src/tools/rust-analyzer/crates/test-fixture/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl ChangeFixture {
207207
meta.edition,
208208
Some(crate_name.clone().into()),
209209
version,
210-
From::from(meta.cfg.clone()),
210+
meta.cfg.clone(),
211211
Some(meta.cfg),
212212
meta.env,
213213
origin,
@@ -247,7 +247,7 @@ impl ChangeFixture {
247247
Edition::CURRENT,
248248
Some(CrateName::new("ra_test_fixture").unwrap().into()),
249249
None,
250-
From::from(default_cfg.clone()),
250+
default_cfg.clone(),
251251
Some(default_cfg),
252252
default_env,
253253
CrateOrigin::Local { repo: None, name: None },

0 commit comments

Comments
 (0)