Skip to content

Commit 7e4b8d8

Browse files
work around prelude hack
1 parent 3378f79 commit 7e4b8d8

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11121112
);
11131113
}
11141114
Scope::StdLibPrelude => {
1115-
if let Some(prelude) = this.prelude {
1115+
if let Some(prelude) = this.prelude.get() {
11161116
let mut tmp_suggestions = Vec::new();
11171117
this.add_module_candidates(prelude, &mut tmp_suggestions, filter_fn, None);
11181118
suggestions.extend(

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
575575
},
576576
Scope::StdLibPrelude => {
577577
let mut result = Err(Determinacy::Determined);
578-
if let Some(prelude) = this.prelude
578+
if let Some(prelude) = this.prelude.get()
579579
&& let Ok(binding) = this.reborrow().resolve_ident_in_module_unadjusted(
580580
ModuleOrUniformRoot::Module(prelude),
581581
ident,

compiler/rustc_resolve/src/imports.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ pub(crate) struct ImportResolver<'r, 'ra, 'tcx> {
4848

4949
// outputs
5050
determined_imports: Vec<Import<'ra>>,
51-
glob_imports: Vec<Import<'ra>>,
51+
glob_import_outputs: Vec<(Module<'ra>, BindingKey, NameBinding<'ra>, bool)>,
52+
glob_res_outputs: Vec<(NodeId, PartialRes)>,
5253
import_bindings: PerNS<Vec<(Module<'ra>, Import<'ra>, PendingBinding<'ra>)>>,
5354
}
5455

5556
struct ImportResolutionOutputs<'ra> {
5657
indeterminate_imports: Vec<Import<'ra>>,
5758
determined_imports: Vec<Import<'ra>>,
58-
glob_imports: Vec<Import<'ra>>,
59+
glob_import_outputs: Vec<(Module<'ra>, BindingKey, NameBinding<'ra>, bool)>,
60+
glob_res_outputs: Vec<(NodeId, PartialRes)>,
5961
import_bindings: PerNS<Vec<(Module<'ra>, Import<'ra>, PendingBinding<'ra>)>>,
6062
}
6163

@@ -65,17 +67,19 @@ impl<'r, 'ra, 'tcx> ImportResolver<'r, 'ra, 'tcx> {
6567
r: cmr,
6668
batch,
6769
determined_imports: Vec::new(),
68-
glob_imports: Vec::new(),
6970
import_bindings: PerNS::default(),
71+
glob_import_outputs: Vec::new(),
72+
glob_res_outputs: Vec::new(),
7073
}
7174
}
7275

7376
fn into_outputs(self) -> ImportResolutionOutputs<'ra> {
7477
ImportResolutionOutputs {
7578
indeterminate_imports: self.batch,
7679
determined_imports: self.determined_imports,
77-
glob_imports: self.glob_imports,
7880
import_bindings: self.import_bindings,
81+
glob_import_outputs: self.glob_import_outputs,
82+
glob_res_outputs: self.glob_res_outputs,
7983
}
8084
}
8185
}
@@ -85,8 +89,12 @@ impl<'ra> ImportResolutionOutputs<'ra> {
8589
r.indeterminate_imports = self.indeterminate_imports;
8690
r.determined_imports.extend(self.determined_imports);
8791

88-
for glob in self.glob_imports {
89-
r.resolve_glob_import(glob);
92+
for (module, key, binding, warn_ambiguity) in self.glob_import_outputs {
93+
let _ = r.try_define_local(module, key.ident.0, key.ns, binding, warn_ambiguity);
94+
}
95+
96+
for (id, res) in self.glob_res_outputs {
97+
r.record_partial_res(id, res);
9098
}
9199

92100
for (ns, import_bindings) in self.import_bindings.into_iter_with() {
@@ -964,14 +972,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
964972
ImportKind::Single { source, target, ref bindings, type_ns_only, .. } => {
965973
(source, target, bindings, type_ns_only)
966974
}
967-
ImportKind::Glob { is_prelude, .. } => {
968-
if is_prelude
969-
&& let ModuleOrUniformRoot::Module(module) =
970-
import.imported_module.get().unwrap()
971-
{
972-
self.r._get_mut_unchecked().prelude = Some(module);
973-
}
974-
self.glob_imports.push(import);
975+
ImportKind::Glob { .. } => {
976+
self.resolve_glob_import(import);
975977
return 0;
976978
}
977979
_ => unreachable!(),
@@ -1565,7 +1567,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15651567
false
15661568
}
15671569

1568-
fn resolve_glob_import(&mut self, import: Import<'ra>) {
1570+
fn resolve_glob_import<'r>(self: &mut ImportResolver<'r, 'ra, 'tcx>, import: Import<'ra>) {
15691571
// This function is only called for glob imports.
15701572
let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() };
15711573

@@ -1587,7 +1589,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15871589
if module == import.parent_scope.module {
15881590
return;
15891591
} else if is_prelude {
1590-
self.prelude = Some(module);
1592+
self.r.prelude.set(Some(module));
15911593
return;
15921594
}
15931595

@@ -1616,18 +1618,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16161618
.resolution(import.parent_scope.module, key)
16171619
.and_then(|r| r.binding())
16181620
.is_some_and(|binding| binding.warn_ambiguity_recursive());
1619-
let _ = self.try_define_local(
1621+
self.glob_import_outputs.push((
16201622
import.parent_scope.module,
1621-
key.ident.0,
1622-
key.ns,
1623+
key,
16231624
imported_binding,
16241625
warn_ambiguity,
1625-
);
1626+
));
16261627
}
16271628
}
16281629

16291630
// Record the destination of this import
1630-
self.record_partial_res(id, PartialRes::new(module.res().unwrap()));
1631+
self.glob_res_outputs.push((id, PartialRes::new(module.res().unwrap())));
16311632
}
16321633

16331634
// Miscellaneous post-processing, including recording re-exports,

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
24852485
.then_some(TypoSuggestion::typo_from_ident(ident.0, res))
24862486
}));
24872487

2488-
if let Some(prelude) = self.r.prelude {
2488+
if let Some(prelude) = self.r.prelude.get() {
24892489
self.r.add_module_candidates(prelude, &mut names, &filter_fn, None);
24902490
}
24912491
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ pub struct Resolver<'ra, 'tcx> {
10581058
/// Assert that we are in speculative resolution mode.
10591059
assert_speculative: bool,
10601060

1061-
prelude: Option<Module<'ra>>,
1061+
prelude: Cell<Option<Module<'ra>>>,
10621062
extern_prelude: FxIndexMap<Macros20NormalizedIdent, ExternPreludeEntry<'ra>>,
10631063

10641064
/// N.B., this is used only for better diagnostics, not name resolution itself.
@@ -1533,7 +1533,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15331533
// AST.
15341534
graph_root,
15351535
assert_speculative: false, // Only set/cleared in Resolver::resolve_imports for now
1536-
prelude: None,
1536+
prelude: Cell::new(None),
15371537
extern_prelude,
15381538

15391539
field_names: Default::default(),
@@ -1881,7 +1881,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18811881
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
18821882
}
18831883
Scope::StdLibPrelude => {
1884-
if let Some(module) = this.prelude {
1884+
if let Some(module) = this.prelude.get() {
18851885
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
18861886
}
18871887
}
@@ -2024,7 +2024,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20242024
if let ImportKind::MacroUse { warn_private: true } = import.kind {
20252025
// Do not report the lint if the macro name resolves in stdlib prelude
20262026
// even without the problematic `macro_use` import.
2027-
let found_in_stdlib_prelude = self.prelude.is_some_and(|prelude| {
2027+
let found_in_stdlib_prelude = self.prelude.get().is_some_and(|prelude| {
20282028
let empty_module = self.empty_module;
20292029
let arenas = self.arenas;
20302030
self.cm()

0 commit comments

Comments
 (0)