resolve: Merge ExternPreludeEntry::only_item into flag_binding
This commit is contained in:
@@ -1014,8 +1014,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||||||
}
|
}
|
||||||
Entry::Vacant(vacant) => vacant.insert(ExternPreludeEntry {
|
Entry::Vacant(vacant) => vacant.insert(ExternPreludeEntry {
|
||||||
item_binding: Some((imported_binding, true)),
|
item_binding: Some((imported_binding, true)),
|
||||||
flag_binding: Cell::new(None),
|
flag_binding: None,
|
||||||
only_item: true,
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1846,7 +1846,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||||||
let extern_prelude_ambiguity = || {
|
let extern_prelude_ambiguity = || {
|
||||||
self.extern_prelude.get(&Macros20NormalizedIdent::new(ident)).is_some_and(|entry| {
|
self.extern_prelude.get(&Macros20NormalizedIdent::new(ident)).is_some_and(|entry| {
|
||||||
entry.item_binding.map(|(b, _)| b) == Some(b1)
|
entry.item_binding.map(|(b, _)| b) == Some(b1)
|
||||||
&& entry.flag_binding.get() == Some(b2)
|
&& entry.flag_binding.as_ref().and_then(|pb| pb.get().binding()) == Some(b2)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let (b1, b2, misc1, misc2, swapped) = if b2.span.is_dummy() && !b1.span.is_dummy() {
|
let (b1, b2, misc1, misc2, swapped) = if b2.span.is_dummy() && !b1.span.is_dummy() {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ use std::sync::Arc;
|
|||||||
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
||||||
use effective_visibilities::EffectiveVisibilitiesVisitor;
|
use effective_visibilities::EffectiveVisibilitiesVisitor;
|
||||||
use errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
use errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
||||||
use imports::{Import, ImportData, ImportKind, NameResolution};
|
use imports::{Import, ImportData, ImportKind, NameResolution, PendingBinding};
|
||||||
use late::{
|
use late::{
|
||||||
ForwardGenericParamBanReason, HasGenericParams, PathSource, PatternSource,
|
ForwardGenericParamBanReason, HasGenericParams, PathSource, PatternSource,
|
||||||
UnnecessaryQualification,
|
UnnecessaryQualification,
|
||||||
@@ -1025,23 +1025,26 @@ impl<'ra> NameBindingData<'ra> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
|
||||||
struct ExternPreludeEntry<'ra> {
|
struct ExternPreludeEntry<'ra> {
|
||||||
/// Binding from an `extern crate` item.
|
/// Binding from an `extern crate` item.
|
||||||
/// The boolean flag is true is `item_binding` is non-redundant, happens either when
|
/// The boolean flag is true is `item_binding` is non-redundant, happens either when
|
||||||
/// `only_item` is true, or when `extern crate` introducing `item_binding` used renaming.
|
/// `flag_binding` is `None`, or when `extern crate` introducing `item_binding` used renaming.
|
||||||
item_binding: Option<(NameBinding<'ra>, /* introduced by item */ bool)>,
|
item_binding: Option<(NameBinding<'ra>, /* introduced by item */ bool)>,
|
||||||
/// Binding from an `--extern` flag, lazily populated on first use.
|
/// Binding from an `--extern` flag, lazily populated on first use.
|
||||||
flag_binding: Cell<Option<NameBinding<'ra>>>,
|
flag_binding: Option<Cell<PendingBinding<'ra>>>,
|
||||||
/// There was no `--extern` flag introducing this name,
|
|
||||||
/// `flag_binding` doesn't need to be populated.
|
|
||||||
only_item: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExternPreludeEntry<'_> {
|
impl ExternPreludeEntry<'_> {
|
||||||
fn introduced_by_item(&self) -> bool {
|
fn introduced_by_item(&self) -> bool {
|
||||||
matches!(self.item_binding, Some((_, true)))
|
matches!(self.item_binding, Some((_, true)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flag() -> Self {
|
||||||
|
ExternPreludeEntry {
|
||||||
|
item_binding: None,
|
||||||
|
flag_binding: Some(Cell::new(PendingBinding::Pending)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DeriveData {
|
struct DeriveData {
|
||||||
@@ -1533,7 +1536,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||||||
&& let name = Symbol::intern(name)
|
&& let name = Symbol::intern(name)
|
||||||
&& name.can_be_raw()
|
&& name.can_be_raw()
|
||||||
{
|
{
|
||||||
Some((Macros20NormalizedIdent::with_dummy_span(name), Default::default()))
|
let ident = Macros20NormalizedIdent::with_dummy_span(name);
|
||||||
|
Some((ident, ExternPreludeEntry::flag()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -1541,11 +1545,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !attr::contains_name(attrs, sym::no_core) {
|
if !attr::contains_name(attrs, sym::no_core) {
|
||||||
extern_prelude
|
let ident = Macros20NormalizedIdent::with_dummy_span(sym::core);
|
||||||
.insert(Macros20NormalizedIdent::with_dummy_span(sym::core), Default::default());
|
extern_prelude.insert(ident, ExternPreludeEntry::flag());
|
||||||
if !attr::contains_name(attrs, sym::no_std) {
|
if !attr::contains_name(attrs, sym::no_std) {
|
||||||
extern_prelude
|
let ident = Macros20NormalizedIdent::with_dummy_span(sym::std);
|
||||||
.insert(Macros20NormalizedIdent::with_dummy_span(sym::std), Default::default());
|
extern_prelude.insert(ident, ExternPreludeEntry::flag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2240,31 +2244,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||||||
|
|
||||||
fn extern_prelude_get_flag(&self, ident: Ident, finalize: bool) -> Option<NameBinding<'ra>> {
|
fn extern_prelude_get_flag(&self, ident: Ident, finalize: bool) -> Option<NameBinding<'ra>> {
|
||||||
let entry = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident));
|
let entry = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident));
|
||||||
entry.and_then(|entry| match entry.flag_binding.get() {
|
entry.and_then(|entry| entry.flag_binding.as_ref()).and_then(|flag_binding| {
|
||||||
Some(binding) => {
|
let binding = match flag_binding.get() {
|
||||||
|
PendingBinding::Ready(binding) => {
|
||||||
if finalize {
|
if finalize {
|
||||||
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span);
|
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span);
|
||||||
}
|
}
|
||||||
Some(binding)
|
binding
|
||||||
}
|
}
|
||||||
None if entry.only_item => None,
|
PendingBinding::Pending => {
|
||||||
None => {
|
|
||||||
let crate_id = if finalize {
|
let crate_id = if finalize {
|
||||||
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span)
|
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span)
|
||||||
} else {
|
} else {
|
||||||
self.cstore_mut().maybe_process_path_extern(self.tcx, ident.name)
|
self.cstore_mut().maybe_process_path_extern(self.tcx, ident.name)
|
||||||
};
|
};
|
||||||
match crate_id {
|
crate_id.map(|crate_id| {
|
||||||
Some(crate_id) => {
|
|
||||||
let res = Res::Def(DefKind::Mod, crate_id.as_def_id());
|
let res = Res::Def(DefKind::Mod, crate_id.as_def_id());
|
||||||
let binding =
|
self.arenas.new_pub_res_binding(res, DUMMY_SP, LocalExpnId::ROOT)
|
||||||
self.arenas.new_pub_res_binding(res, DUMMY_SP, LocalExpnId::ROOT);
|
})
|
||||||
entry.flag_binding.set(Some(binding));
|
|
||||||
Some(binding)
|
|
||||||
}
|
|
||||||
None => finalize.then_some(self.dummy_binding),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
flag_binding.set(PendingBinding::Ready(binding));
|
||||||
|
binding.or_else(|| finalize.then_some(self.dummy_binding))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user