Skip to content

Commit f7e883a

Browse files
authored
Merge pull request #19368 from Veykril/push-pkooqmlxszps
refactor: Remove `CrateGraphBuilder::iter_mut`
2 parents fcd6e94 + cd0582c commit f7e883a

File tree

31 files changed

+97
-1323
lines changed

31 files changed

+97
-1323
lines changed

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

Lines changed: 4 additions & 10 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
}
@@ -311,6 +311,7 @@ pub struct CrateData<Id> {
311311
pub type CrateDataBuilder = CrateData<CrateBuilderId>;
312312
pub type BuiltCrateData = CrateData<Crate>;
313313

314+
/// Crate data unrelated to analysis.
314315
#[derive(Debug, Clone, PartialEq, Eq)]
315316
pub struct ExtraCrateData {
316317
pub version: Option<String>,
@@ -402,9 +403,8 @@ pub struct Crate {
402403
// This is in `Arc` because it is shared for all crates in a workspace.
403404
#[return_ref]
404405
pub workspace_data: Arc<CrateWorkspaceData>,
405-
// FIXME: Remove this `Arc`.
406406
#[return_ref]
407-
pub cfg_options: Arc<CfgOptions>,
407+
pub cfg_options: CfgOptions,
408408
#[return_ref]
409409
pub env: Env,
410410
}
@@ -420,7 +420,7 @@ impl CrateGraphBuilder {
420420
edition: Edition,
421421
display_name: Option<CrateDisplayName>,
422422
version: Option<String>,
423-
cfg_options: Arc<CfgOptions>,
423+
cfg_options: CfgOptions,
424424
potential_cfg_options: Option<CfgOptions>,
425425
mut env: Env,
426426
origin: CrateOrigin,
@@ -601,12 +601,6 @@ impl CrateGraphBuilder {
601601
self.arena.iter().map(|(idx, _)| idx)
602602
}
603603

604-
// FIXME: used for fixing up the toolchain sysroot, should be removed and done differently
605-
#[doc(hidden)]
606-
pub fn iter_mut(&mut self) -> impl Iterator<Item = (CrateBuilderId, &mut CrateBuilder)> + '_ {
607-
self.arena.iter_mut()
608-
}
609-
610604
/// Returns an iterator over all transitive dependencies of the given crate,
611605
/// including the crate itself.
612606
pub fn transitive_deps(&self, of: CrateBuilderId) -> impl Iterator<Item = CrateBuilderId> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl fmt::Display for InactiveReason {
264264
}
265265

266266
/// A `CfgOptions` that implements `Hash`, for the sake of hashing only.
267-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
267+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
268268
pub struct HashableCfgOptions {
269269
_enabled: Box<[CfgAtom]>,
270270
}

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/cargo_workspace.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub struct CargoWorkspace {
3535
target_directory: AbsPathBuf,
3636
manifest_path: ManifestPath,
3737
is_virtual_workspace: bool,
38+
/// Whether this workspace represents the sysroot workspace.
39+
is_sysroot: bool,
3840
/// Environment variables set in the `.cargo/config` file.
3941
config_env: Env,
4042
}
@@ -418,6 +420,7 @@ impl CargoWorkspace {
418420
mut meta: cargo_metadata::Metadata,
419421
ws_manifest_path: ManifestPath,
420422
cargo_config_env: Env,
423+
is_sysroot: bool,
421424
) -> CargoWorkspace {
422425
let mut pkg_by_id = FxHashMap::default();
423426
let mut packages = Arena::default();
@@ -539,6 +542,7 @@ impl CargoWorkspace {
539542
target_directory,
540543
manifest_path: ws_manifest_path,
541544
is_virtual_workspace,
545+
is_sysroot,
542546
config_env: cargo_config_env,
543547
}
544548
}
@@ -632,4 +636,8 @@ impl CargoWorkspace {
632636
pub fn env(&self) -> &Env {
633637
&self.config_env
634638
}
639+
640+
pub fn is_sysroot(&self) -> bool {
641+
self.is_sysroot
642+
}
635643
}

0 commit comments

Comments
 (0)