Skip to content

Commit 710416c

Browse files
move used_extern_options from Resolver to CStore
1 parent bf5e6cc commit 710416c

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-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: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,10 @@ pub struct Resolver<'ra, 'tcx> {
11101110
builtin_types_bindings: FxHashMap<Symbol, NameBinding<'ra>>,
11111111
builtin_attrs_bindings: FxHashMap<Symbol, NameBinding<'ra>>,
11121112
registered_tool_bindings: FxHashMap<Ident, NameBinding<'ra>>,
1113-
used_extern_options: FxHashSet<Symbol>,
1113+
/// Binding for implicitly declared names that come with a module,
1114+
/// like `self` (not yet used), or `crate`/`$crate` (for root modules).
1115+
module_self_bindings: FxHashMap<Module<'ra>, NameBinding<'ra>>,
1116+
11141117
macro_names: FxHashSet<Ident>,
11151118
builtin_macros: FxHashMap<Symbol, SyntaxExtensionKind>,
11161119
registered_tools: &'tcx RegisteredTools,
@@ -1546,7 +1549,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15461549
(*ident, binding)
15471550
})
15481551
.collect(),
1549-
used_extern_options: Default::default(),
1552+
module_self_bindings,
15501553
macro_names: FxHashSet::default(),
15511554
builtin_macros: Default::default(),
15521555
registered_tools,
@@ -1733,12 +1736,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17331736
StableHashingContext::new(self.tcx.sess, self.tcx.untracked())
17341737
}
17351738

1736-
fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
1737-
f(&mut CrateLoader::new(
1738-
self.tcx,
1739-
&mut CStore::from_tcx_mut(self.tcx),
1740-
&mut self.used_extern_options,
1741-
))
1739+
fn crate_loader<T>(&self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T {
1740+
f(&mut CrateLoader::new(self.tcx, &mut CStore::from_tcx_mut(self.tcx)))
17421741
}
17431742

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

0 commit comments

Comments
 (0)