Skip to content

Commit 94bb516

Browse files
address review
1 parent 7e4b8d8 commit 94bb516

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-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.get() {
1115+
if let Some(prelude) = this.prelude {
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.get()
578+
if let Some(prelude) = this.prelude
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: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::mem;
55
use std::ops::Deref;
66

77
use rustc_ast::NodeId;
8-
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
8+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
99
use rustc_data_structures::intern::Interned;
1010
use rustc_errors::codes::*;
1111
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
@@ -47,16 +47,20 @@ pub(crate) struct ImportResolver<'r, 'ra, 'tcx> {
4747
batch: Vec<Import<'ra>>, // a.k.a. indeterminate_imports, also treated as output
4848

4949
// outputs
50+
prelude: Option<Module<'ra>>,
5051
determined_imports: Vec<Import<'ra>>,
51-
glob_import_outputs: Vec<(Module<'ra>, BindingKey, NameBinding<'ra>, bool)>,
52+
module_glob_importers: FxIndexMap<Module<'ra>, Vec<Import<'ra>>>,
53+
glob_import_bindings: Vec<(Module<'ra>, BindingKey, NameBinding<'ra>, bool)>,
5254
glob_res_outputs: Vec<(NodeId, PartialRes)>,
5355
import_bindings: PerNS<Vec<(Module<'ra>, Import<'ra>, PendingBinding<'ra>)>>,
5456
}
5557

5658
struct ImportResolutionOutputs<'ra> {
59+
prelude: Option<Module<'ra>>,
5760
indeterminate_imports: Vec<Import<'ra>>,
5861
determined_imports: Vec<Import<'ra>>,
59-
glob_import_outputs: Vec<(Module<'ra>, BindingKey, NameBinding<'ra>, bool)>,
62+
module_glob_importers: FxIndexMap<Module<'ra>, Vec<Import<'ra>>>,
63+
glob_import_bindings: Vec<(Module<'ra>, BindingKey, NameBinding<'ra>, bool)>,
6064
glob_res_outputs: Vec<(NodeId, PartialRes)>,
6165
import_bindings: PerNS<Vec<(Module<'ra>, Import<'ra>, PendingBinding<'ra>)>>,
6266
}
@@ -66,20 +70,24 @@ impl<'r, 'ra, 'tcx> ImportResolver<'r, 'ra, 'tcx> {
6670
ImportResolver {
6771
r: cmr,
6872
batch,
69-
determined_imports: Vec::new(),
70-
import_bindings: PerNS::default(),
71-
glob_import_outputs: Vec::new(),
72-
glob_res_outputs: Vec::new(),
73+
prelude: None,
74+
determined_imports: Default::default(),
75+
module_glob_importers: Default::default(),
76+
glob_import_bindings: Default::default(),
77+
glob_res_outputs: Default::default(),
78+
import_bindings: Default::default(),
7379
}
7480
}
7581

7682
fn into_outputs(self) -> ImportResolutionOutputs<'ra> {
7783
ImportResolutionOutputs {
84+
prelude: self.prelude,
7885
indeterminate_imports: self.batch,
7986
determined_imports: self.determined_imports,
80-
import_bindings: self.import_bindings,
81-
glob_import_outputs: self.glob_import_outputs,
87+
module_glob_importers: self.module_glob_importers,
88+
glob_import_bindings: self.glob_import_bindings,
8289
glob_res_outputs: self.glob_res_outputs,
90+
import_bindings: self.import_bindings,
8391
}
8492
}
8593
}
@@ -89,7 +97,17 @@ impl<'ra> ImportResolutionOutputs<'ra> {
8997
r.indeterminate_imports = self.indeterminate_imports;
9098
r.determined_imports.extend(self.determined_imports);
9199

92-
for (module, key, binding, warn_ambiguity) in self.glob_import_outputs {
100+
// It's possible this particular round didn't set the prelude, so we should not
101+
// unset it in the main resolver.
102+
if self.prelude.is_some() {
103+
r.prelude = self.prelude;
104+
}
105+
106+
for (module, glob_importers) in self.module_glob_importers {
107+
module.glob_importers.borrow_mut().extend(glob_importers);
108+
}
109+
110+
for (module, key, binding, warn_ambiguity) in self.glob_import_bindings {
93111
let _ = r.try_define_local(module, key.ident.0, key.ns, binding, warn_ambiguity);
94112
}
95113

@@ -648,12 +666,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
648666
let mut prev_indeterminate_count = usize::MAX;
649667
let mut indeterminate_count = self.indeterminate_imports.len() * 3;
650668
while indeterminate_count < prev_indeterminate_count {
651-
self.assert_speculative = true;
652669
prev_indeterminate_count = indeterminate_count;
653670
let batch = mem::take(&mut self.indeterminate_imports);
671+
self.assert_speculative = true;
654672
let (outputs, count) = ImportResolver::new(self.cm(), batch).resolve_batch();
655-
indeterminate_count = count;
656673
self.assert_speculative = false;
674+
indeterminate_count = count;
657675
outputs.commit(self);
658676
}
659677
}
@@ -1589,12 +1607,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15891607
if module == import.parent_scope.module {
15901608
return;
15911609
} else if is_prelude {
1592-
self.r.prelude.set(Some(module));
1610+
self.prelude = Some(module);
15931611
return;
15941612
}
15951613

15961614
// Add to module's glob_importers
1597-
module.glob_importers.borrow_mut().push(import);
1615+
self.module_glob_importers.entry(module).or_default().push(import);
15981616

15991617
// Ensure that `resolutions` isn't borrowed during `try_define`,
16001618
// since it might get updated via a glob cycle.
@@ -1618,7 +1636,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16181636
.resolution(import.parent_scope.module, key)
16191637
.and_then(|r| r.binding())
16201638
.is_some_and(|binding| binding.warn_ambiguity_recursive());
1621-
self.glob_import_outputs.push((
1639+
self.glob_import_bindings.push((
16221640
import.parent_scope.module,
16231641
key,
16241642
imported_binding,

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.get() {
2488+
if let Some(prelude) = self.r.prelude {
24892489
self.r.add_module_candidates(prelude, &mut names, &filter_fn, None);
24902490
}
24912491
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 4 additions & 10 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: Cell<Option<Module<'ra>>>,
1061+
prelude: 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: Cell::new(None),
1536+
prelude: 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.get() {
1884+
if let Some(module) = this.prelude {
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.get().is_some_and(|prelude| {
2027+
let found_in_stdlib_prelude = self.prelude.is_some_and(|prelude| {
20282028
let empty_module = self.empty_module;
20292029
let arenas = self.arenas;
20302030
self.cm()
@@ -2501,12 +2501,6 @@ mod ref_mut {
25012501
true => self.p,
25022502
}
25032503
}
2504-
2505-
/// Returns a mutable reference to the inner value without checking if
2506-
/// it's in a mutable state.
2507-
pub(crate) fn _get_mut_unchecked(&mut self) -> &mut T {
2508-
self.p
2509-
}
25102504
}
25112505
}
25122506

0 commit comments

Comments
 (0)