"Cachify" ExternPreludeEntry.binding through a Cell.
This commit is contained in:
@@ -984,18 +984,17 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||
// more details: https://github.com/rust-lang/rust/pull/111761
|
||||
return;
|
||||
}
|
||||
let entry = self
|
||||
.r
|
||||
.extern_prelude
|
||||
.entry(ident)
|
||||
.or_insert(ExternPreludeEntry { binding: None, introduced_by_item: true });
|
||||
let entry = self.r.extern_prelude.entry(ident).or_insert(ExternPreludeEntry {
|
||||
binding: Cell::new(None),
|
||||
introduced_by_item: true,
|
||||
});
|
||||
if orig_name.is_some() {
|
||||
entry.introduced_by_item = true;
|
||||
}
|
||||
// Binding from `extern crate` item in source code can replace
|
||||
// a binding from `--extern` on command line here.
|
||||
if !entry.is_import() {
|
||||
entry.binding = Some(imported_binding)
|
||||
entry.binding.set(Some(imported_binding));
|
||||
} else if ident.name != kw::Underscore {
|
||||
self.r.dcx().span_delayed_bug(
|
||||
item.span,
|
||||
|
||||
@@ -1009,13 +1009,13 @@ impl<'ra> NameBindingData<'ra> {
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
struct ExternPreludeEntry<'ra> {
|
||||
binding: Option<NameBinding<'ra>>,
|
||||
binding: Cell<Option<NameBinding<'ra>>>,
|
||||
introduced_by_item: bool,
|
||||
}
|
||||
|
||||
impl ExternPreludeEntry<'_> {
|
||||
fn is_import(&self) -> bool {
|
||||
self.binding.is_some_and(|binding| binding.is_import())
|
||||
self.binding.get().is_some_and(|binding| binding.is_import())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2006,7 +2006,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
// but not introduce it, as used if they are accessed from lexical scope.
|
||||
if used == Used::Scope {
|
||||
if let Some(entry) = self.extern_prelude.get(&ident.normalize_to_macros_2_0()) {
|
||||
if !entry.introduced_by_item && entry.binding == Some(used_binding) {
|
||||
if !entry.introduced_by_item && entry.binding.get() == Some(used_binding) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2170,7 +2170,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
|
||||
let norm_ident = ident.normalize_to_macros_2_0();
|
||||
let binding = self.extern_prelude.get(&norm_ident).cloned().and_then(|entry| {
|
||||
Some(if let Some(binding) = entry.binding {
|
||||
Some(if let Some(binding) = entry.binding.get() {
|
||||
if finalize {
|
||||
if !entry.is_import() {
|
||||
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span);
|
||||
@@ -2195,8 +2195,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
})
|
||||
});
|
||||
|
||||
if let Some(entry) = self.extern_prelude.get_mut(&norm_ident) {
|
||||
entry.binding = binding;
|
||||
if let Some(entry) = self.extern_prelude.get(&norm_ident) {
|
||||
entry.binding.set(binding);
|
||||
}
|
||||
|
||||
binding
|
||||
|
||||
Reference in New Issue
Block a user