Skip to content

Commit 951f62d

Browse files
move used_extern_options from Resolver to CStore
1 parent a9fb610 commit 951f62d

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub struct CStore {
7070

7171
/// Unused externs of the crate
7272
unused_externs: Vec<Symbol>,
73+
74+
used_extern_options: FxHashSet<Symbol>,
7375
}
7476

7577
impl std::fmt::Debug for CStore {
@@ -83,7 +85,6 @@ pub struct CrateLoader<'a, 'tcx: 'a> {
8385
tcx: TyCtxt<'tcx>,
8486
// Mutable output.
8587
cstore: &'a mut CStore,
86-
used_extern_options: &'a mut FxHashSet<Symbol>,
8788
}
8889

8990
impl<'a, 'tcx> std::ops::Deref for CrateLoader<'a, 'tcx> {
@@ -495,17 +496,14 @@ impl CStore {
495496
has_global_allocator: false,
496497
has_alloc_error_handler: false,
497498
unused_externs: Vec::new(),
499+
used_extern_options: Default::default(),
498500
}
499501
}
500502
}
501503

502504
impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
503-
pub fn new(
504-
tcx: TyCtxt<'tcx>,
505-
cstore: &'a mut CStore,
506-
used_extern_options: &'a mut FxHashSet<Symbol>,
507-
) -> Self {
508-
CrateLoader { tcx, cstore, used_extern_options }
505+
pub fn new(tcx: TyCtxt<'tcx>, cstore: &'a mut CStore) -> Self {
506+
CrateLoader { tcx, cstore }
509507
}
510508

511509
fn existing_match(&self, name: Symbol, hash: Option<Svh>, kind: PathKind) -> Option<CrateNum> {
@@ -753,7 +751,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
753751
dep_kind: CrateDepKind,
754752
origin: CrateOrigin<'_>,
755753
) -> Option<CrateNum> {
756-
self.used_extern_options.insert(name);
754+
self.cstore.used_extern_options.insert(name);
757755
match self.maybe_resolve_crate(name, dep_kind, origin) {
758756
Ok(cnum) => {
759757
self.cstore.set_used_recursively(cnum);
@@ -1143,7 +1141,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
11431141
for (name, entry) in self.sess.opts.externs.iter() {
11441142
if entry.force {
11451143
let name_interned = Symbol::intern(name);
1146-
if !self.used_extern_options.contains(&name_interned) {
1144+
if !self.cstore.used_extern_options.contains(&name_interned) {
11471145
self.resolve_crate(
11481146
name_interned,
11491147
DUMMY_SP,
@@ -1206,7 +1204,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
12061204
continue;
12071205
}
12081206
let name_interned = Symbol::intern(name);
1209-
if self.used_extern_options.contains(&name_interned) {
1207+
if self.cstore.used_extern_options.contains(&name_interned) {
12101208
continue;
12111209
}
12121210

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,6 @@ pub struct Resolver<'ra, 'tcx> {
11301130
/// like `self` (not yet used), or `crate`/`$crate` (for root modules).
11311131
module_self_bindings: FxHashMap<Module<'ra>, NameBinding<'ra>>,
11321132

1133-
used_extern_options: FxHashSet<Symbol>,
11341133
macro_names: FxHashSet<Ident>,
11351134
builtin_macros: FxHashMap<Symbol, SyntaxExtensionKind>,
11361135
registered_tools: &'tcx RegisteredTools,
@@ -1548,7 +1547,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15481547
.collect(),
15491548
module_self_bindings,
15501549

1551-
used_extern_options: Default::default(),
15521550
macro_names: FxHashSet::default(),
15531551
builtin_macros: Default::default(),
15541552
registered_tools,
@@ -1728,12 +1726,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17281726
StableHashingContext::new(self.tcx.sess, self.tcx.untracked())
17291727
}
17301728

1731-
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
1732-
f(&mut CrateLoader::new(
1733-
self.tcx,
1734-
&mut CStore::from_tcx_mut(self.tcx),
1735-
&mut self.used_extern_options,
1736-
))
1729+
fn crate_loader<T>(&self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
1730+
f(&mut CrateLoader::new(self.tcx, &mut CStore::from_tcx_mut(self.tcx)))
17371731
}
17381732

17391733
fn cstore(&self) -> FreezeReadGuard<'_, CStore> {

0 commit comments

Comments
 (0)