Update more function names and fields from bindings to declarations
This commit is contained in:
parent
a67e289b4d
commit
a0ea3b0635
10 changed files with 284 additions and 296 deletions
|
|
@ -44,20 +44,22 @@ use crate::{
|
|||
type Res = def::Res<NodeId>;
|
||||
|
||||
impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
|
||||
/// otherwise, reports an error.
|
||||
pub(crate) fn define_binding_local(
|
||||
/// Attempt to put the declaration with the given name and namespace into the module,
|
||||
/// and report an error in case of a collision.
|
||||
pub(crate) fn plant_decl_into_local_module(
|
||||
&mut self,
|
||||
parent: Module<'ra>,
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
decl: Decl<'ra>,
|
||||
) {
|
||||
if let Err(old_binding) = self.try_define_local(parent, ident, ns, decl, false) {
|
||||
self.report_conflict(parent, ident, ns, old_binding, decl);
|
||||
if let Err(old_decl) = self.try_plant_decl_into_local_module(parent, ident, ns, decl, false)
|
||||
{
|
||||
self.report_conflict(parent, ident, ns, old_decl, decl);
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a name definitinon from the given components, and put it into the local module.
|
||||
fn define_local(
|
||||
&mut self,
|
||||
parent: Module<'ra>,
|
||||
|
|
@ -68,10 +70,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
span: Span,
|
||||
expn_id: LocalExpnId,
|
||||
) {
|
||||
let binding = self.arenas.new_def_decl(res, vis.to_def_id(), span, expn_id);
|
||||
self.define_binding_local(parent, ident, ns, binding);
|
||||
let decl = self.arenas.new_def_decl(res, vis.to_def_id(), span, expn_id);
|
||||
self.plant_decl_into_local_module(parent, ident, ns, decl);
|
||||
}
|
||||
|
||||
/// Create a name definitinon from the given components, and put it into the extern module.
|
||||
fn define_extern(
|
||||
&self,
|
||||
parent: Module<'ra>,
|
||||
|
|
@ -84,7 +87,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
expansion: LocalExpnId,
|
||||
ambiguity: Option<Decl<'ra>>,
|
||||
) {
|
||||
let binding = self.arenas.alloc_decl(DeclData {
|
||||
let decl = self.arenas.alloc_decl(DeclData {
|
||||
kind: DeclKind::Def(res),
|
||||
ambiguity,
|
||||
// External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
|
||||
|
|
@ -101,8 +104,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
if self
|
||||
.resolution_or_default(parent, key)
|
||||
.borrow_mut_unchecked()
|
||||
.non_glob_binding
|
||||
.replace(binding)
|
||||
.non_glob_decl
|
||||
.replace(decl)
|
||||
.is_some()
|
||||
{
|
||||
span_bug!(span, "an external binding was already defined");
|
||||
|
|
@ -691,7 +694,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
let kind = ImportKind::Single {
|
||||
source: source.ident,
|
||||
target: ident,
|
||||
bindings: Default::default(),
|
||||
decls: Default::default(),
|
||||
type_ns_only,
|
||||
nested,
|
||||
id,
|
||||
|
|
@ -1019,7 +1022,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
self.r.import_use_map.insert(import, Used::Other);
|
||||
}
|
||||
self.r.potentially_unused_imports.push(import);
|
||||
let imported_binding = self.r.import(decl, import);
|
||||
let import_decl = self.r.new_import_decl(decl, import);
|
||||
if ident.name != kw::Underscore && parent == self.r.graph_root {
|
||||
let norm_ident = Macros20NormalizedIdent::new(ident);
|
||||
// FIXME: this error is technically unnecessary now when extern prelude is split into
|
||||
|
|
@ -1042,17 +1045,17 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
let msg = format!("extern crate `{ident}` already in extern prelude");
|
||||
self.r.tcx.dcx().span_delayed_bug(item.span, msg);
|
||||
} else {
|
||||
entry.item_decl = Some((imported_binding, orig_name.is_some()));
|
||||
entry.item_decl = Some((import_decl, orig_name.is_some()));
|
||||
}
|
||||
entry
|
||||
}
|
||||
Entry::Vacant(vacant) => vacant.insert(ExternPreludeEntry {
|
||||
item_decl: Some((imported_binding, true)),
|
||||
item_decl: Some((import_decl, true)),
|
||||
flag_decl: None,
|
||||
}),
|
||||
};
|
||||
}
|
||||
self.r.define_binding_local(parent, ident, TypeNS, imported_binding);
|
||||
self.r.plant_decl_into_local_module(parent, ident, TypeNS, import_decl);
|
||||
}
|
||||
|
||||
/// Constructs the reduced graph for one foreign item.
|
||||
|
|
@ -1167,8 +1170,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
}
|
||||
macro_use_import(this, span, true)
|
||||
};
|
||||
let import_binding = this.r.import(binding, import);
|
||||
this.add_macro_use_decl(ident.name, import_binding, span, allow_shadowing);
|
||||
let import_decl = this.r.new_import_decl(binding, import);
|
||||
this.add_macro_use_decl(ident.name, import_decl, span, allow_shadowing);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
@ -1183,13 +1186,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
if let Ok(binding) = result {
|
||||
let import = macro_use_import(self, ident.span, false);
|
||||
self.r.potentially_unused_imports.push(import);
|
||||
let imported_binding = self.r.import(binding, import);
|
||||
self.add_macro_use_decl(
|
||||
ident.name,
|
||||
imported_binding,
|
||||
ident.span,
|
||||
allow_shadowing,
|
||||
);
|
||||
let import_decl = self.r.new_import_decl(binding, import);
|
||||
self.add_macro_use_decl(ident.name, import_decl, ident.span, allow_shadowing);
|
||||
} else {
|
||||
self.r.dcx().emit_err(errors::ImportedMacroNotFound { span: ident.span });
|
||||
}
|
||||
|
|
@ -1319,8 +1317,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
vis_span: item.vis.span,
|
||||
});
|
||||
self.r.import_use_map.insert(import, Used::Other);
|
||||
let import_binding = self.r.import(decl, import);
|
||||
self.r.define_binding_local(self.r.graph_root, ident, MacroNS, import_binding);
|
||||
let import_decl = self.r.new_import_decl(decl, import);
|
||||
self.r.plant_decl_into_local_module(self.r.graph_root, ident, MacroNS, import_decl);
|
||||
} else {
|
||||
self.r.check_reserved_macro_name(ident, res);
|
||||
self.insert_unused_macro(ident, def_id, item.id);
|
||||
|
|
|
|||
|
|
@ -514,8 +514,8 @@ impl Resolver<'_, '_> {
|
|||
let mut check_redundant_imports = FxIndexSet::default();
|
||||
for module in &self.local_modules {
|
||||
for (_key, resolution) in self.resolutions(*module).borrow().iter() {
|
||||
if let Some(binding) = resolution.borrow().best_binding()
|
||||
&& let DeclKind::Import { import, .. } = binding.kind
|
||||
if let Some(decl) = resolution.borrow().best_decl()
|
||||
&& let DeclKind::Import { import, .. } = decl.kind
|
||||
&& let ImportKind::Single { id, .. } = import.kind
|
||||
{
|
||||
if let Some(unused_import) = unused_imports.get(&import.root_id)
|
||||
|
|
@ -542,8 +542,8 @@ impl Resolver<'_, '_> {
|
|||
// Deleting both unused imports and unnecessary segments of an item may result
|
||||
// in the item not being found.
|
||||
for unn_qua in &self.potentially_unnecessary_qualifications {
|
||||
if let LateDecl::Decl(name_binding) = unn_qua.binding
|
||||
&& let DeclKind::Import { import, .. } = name_binding.kind
|
||||
if let LateDecl::Decl(decl) = unn_qua.decl
|
||||
&& let DeclKind::Import { import, .. } = decl.kind
|
||||
&& (is_unused_import(import, &unused_imports)
|
||||
|| is_redundant_import(import, &redundant_imports))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1195,13 +1195,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
// Never recommend deprecated helper attributes.
|
||||
}
|
||||
Scope::MacroRules(macro_rules_scope) => {
|
||||
if let MacroRulesScope::Def(macro_rules_binding) = macro_rules_scope.get() {
|
||||
let res = macro_rules_binding.decl.res();
|
||||
if let MacroRulesScope::Def(macro_rules_def) = macro_rules_scope.get() {
|
||||
let res = macro_rules_def.decl.res();
|
||||
if filter_fn(res) {
|
||||
suggestions.push(TypoSuggestion::typo_from_ident(
|
||||
macro_rules_binding.ident,
|
||||
res,
|
||||
))
|
||||
suggestions
|
||||
.push(TypoSuggestion::typo_from_ident(macro_rules_def.ident, res))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1581,9 +1579,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
|(key, name_resolution)| {
|
||||
if key.ns == TypeNS
|
||||
&& key.ident == ident
|
||||
&& let Some(binding) = name_resolution.borrow().best_binding()
|
||||
&& let Some(decl) = name_resolution.borrow().best_decl()
|
||||
{
|
||||
match binding.res() {
|
||||
match decl.res() {
|
||||
// No disambiguation needed if the identically named item we
|
||||
// found in scope actually refers to the crate in question.
|
||||
Res::Def(_, def_id) => def_id != crate_def_id,
|
||||
|
|
@ -2087,7 +2085,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'ra>) {
|
||||
let PrivacyError {
|
||||
ident,
|
||||
binding,
|
||||
decl,
|
||||
outermost_res,
|
||||
parent_scope,
|
||||
single_nested,
|
||||
|
|
@ -2095,8 +2093,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ref source,
|
||||
} = *privacy_error;
|
||||
|
||||
let res = binding.res();
|
||||
let ctor_fields_span = self.ctor_fields_span(binding);
|
||||
let res = decl.res();
|
||||
let ctor_fields_span = self.ctor_fields_span(decl);
|
||||
let plain_descr = res.descr().to_string();
|
||||
let nonimport_descr =
|
||||
if ctor_fields_span.is_some() { plain_descr + " constructor" } else { plain_descr };
|
||||
|
|
@ -2104,7 +2102,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
let get_descr = |b: Decl<'_>| if b.is_import() { &import_descr } else { &nonimport_descr };
|
||||
|
||||
// Print the primary message.
|
||||
let ident_descr = get_descr(binding);
|
||||
let ident_descr = get_descr(decl);
|
||||
let mut err =
|
||||
self.dcx().create_err(errors::IsPrivate { span: ident.span, ident_descr, ident });
|
||||
|
||||
|
|
@ -2204,8 +2202,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
}
|
||||
|
||||
// Print the whole import chain to make it easier to see what happens.
|
||||
let first_binding = binding;
|
||||
let mut next_binding = Some(binding);
|
||||
let first_binding = decl;
|
||||
let mut next_binding = Some(decl);
|
||||
let mut next_ident = ident;
|
||||
let mut path = vec![];
|
||||
while let Some(binding) = next_binding {
|
||||
|
|
@ -2413,7 +2411,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'ra>,
|
||||
ribs: Option<&PerNS<Vec<Rib<'ra>>>>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
module: Option<ModuleOrUniformRoot<'ra>>,
|
||||
failed_segment_idx: usize,
|
||||
|
|
@ -2509,7 +2507,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns_to_try,
|
||||
parent_scope,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
.ok()
|
||||
|
|
@ -2523,7 +2521,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
None,
|
||||
&ribs[ns_to_try],
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
diag_metadata,
|
||||
) {
|
||||
// we found a locally-imported or available item/module
|
||||
|
|
@ -2538,7 +2536,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
None,
|
||||
false,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
.ok()
|
||||
|
|
@ -2574,7 +2572,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
None,
|
||||
&ribs[ValueNS],
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
diag_metadata,
|
||||
)
|
||||
} else {
|
||||
|
|
@ -2642,7 +2640,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
None,
|
||||
false,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
) {
|
||||
let descr = binding.res().descr();
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ impl ParentId<'_> {
|
|||
pub(crate) struct EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
||||
r: &'a mut Resolver<'ra, 'tcx>,
|
||||
def_effective_visibilities: EffectiveVisibilities,
|
||||
/// While walking import chains we need to track effective visibilities per-binding, and def id
|
||||
/// While walking import chains we need to track effective visibilities per-decl, and def id
|
||||
/// keys in `Resolver::effective_visibilities` are not enough for that, because multiple
|
||||
/// bindings can correspond to a single def id in imports. So we keep a separate table.
|
||||
/// declarations can correspond to a single def id in imports. So we keep a separate table.
|
||||
import_effective_visibilities: EffectiveVisibilities<Decl<'ra>>,
|
||||
// It's possible to recalculate this at any point, but it's relatively expensive.
|
||||
current_private_vis: Visibility,
|
||||
|
|
@ -91,9 +91,9 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
|||
let mut exported_ambiguities = FxHashSet::default();
|
||||
|
||||
// Update visibilities for import def ids. These are not used during the
|
||||
// `EffectiveVisibilitiesVisitor` pass, because we have more detailed binding-based
|
||||
// `EffectiveVisibilitiesVisitor` pass, because we have more detailed declaration-based
|
||||
// information, but are used by later passes. Effective visibility of an import def id
|
||||
// is the maximum value among visibilities of bindings corresponding to that def id.
|
||||
// is the maximum value among visibilities of declarations corresponding to that def id.
|
||||
for (decl, eff_vis) in visitor.import_effective_visibilities.iter() {
|
||||
let DeclKind::Import { import, .. } = decl.kind else { unreachable!() };
|
||||
if !decl.is_ambiguity_recursive() {
|
||||
|
|
@ -110,12 +110,12 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
|||
exported_ambiguities
|
||||
}
|
||||
|
||||
/// Update effective visibilities of bindings in the given module,
|
||||
/// Update effective visibilities of name declarations in the given module,
|
||||
/// including their whole reexport chains.
|
||||
fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) {
|
||||
let module = self.r.expect_module(module_id.to_def_id());
|
||||
for (_, name_resolution) in self.r.resolutions(module).borrow().iter() {
|
||||
let Some(mut binding) = name_resolution.borrow().binding() else {
|
||||
let Some(mut decl) = name_resolution.borrow().binding() else {
|
||||
continue;
|
||||
};
|
||||
// Set the given effective visibility level to `Level::Direct` and
|
||||
|
|
@ -125,28 +125,27 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
|
|||
// If the binding is ambiguous, put the root ambiguity binding and all reexports
|
||||
// leading to it into the table. They are used by the `ambiguous_glob_reexports`
|
||||
// lint. For all bindings added to the table this way `is_ambiguity` returns true.
|
||||
let is_ambiguity =
|
||||
|binding: Decl<'ra>, warn: bool| binding.ambiguity.is_some() && !warn;
|
||||
let is_ambiguity = |decl: Decl<'ra>, warn: bool| decl.ambiguity.is_some() && !warn;
|
||||
let mut parent_id = ParentId::Def(module_id);
|
||||
let mut warn_ambiguity = binding.warn_ambiguity;
|
||||
while let DeclKind::Import { binding: nested_binding, .. } = binding.kind {
|
||||
self.update_import(binding, parent_id);
|
||||
let mut warn_ambiguity = decl.warn_ambiguity;
|
||||
while let DeclKind::Import { binding: nested_binding, .. } = decl.kind {
|
||||
self.update_import(decl, parent_id);
|
||||
|
||||
if is_ambiguity(binding, warn_ambiguity) {
|
||||
if is_ambiguity(decl, warn_ambiguity) {
|
||||
// Stop at the root ambiguity, further bindings in the chain should not
|
||||
// be reexported because the root ambiguity blocks any access to them.
|
||||
// (Those further bindings are most likely not ambiguities themselves.)
|
||||
break;
|
||||
}
|
||||
|
||||
parent_id = ParentId::Import(binding);
|
||||
binding = nested_binding;
|
||||
parent_id = ParentId::Import(decl);
|
||||
decl = nested_binding;
|
||||
warn_ambiguity |= nested_binding.warn_ambiguity;
|
||||
}
|
||||
if !is_ambiguity(binding, warn_ambiguity)
|
||||
&& let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local())
|
||||
if !is_ambiguity(decl, warn_ambiguity)
|
||||
&& let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local())
|
||||
{
|
||||
self.update_def(def_id, binding.vis.expect_local(), parent_id);
|
||||
self.update_def(def_id, decl.vis.expect_local(), parent_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope: &ParentScope<'ra>,
|
||||
finalize: Option<Finalize>,
|
||||
ribs: &[Rib<'ra>],
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
diag_metadata: Option<&DiagMetadata<'_>>,
|
||||
) -> Option<LateDecl<'ra>> {
|
||||
let orig_ident = ident;
|
||||
|
|
@ -345,7 +345,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
None,
|
||||
)
|
||||
{
|
||||
|
|
@ -363,7 +363,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
None,
|
||||
)
|
||||
.ok()
|
||||
|
|
@ -391,7 +391,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope: &ParentScope<'ra>,
|
||||
finalize: Option<Finalize>,
|
||||
force: bool,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> Result<Decl<'ra>, Determinacy> {
|
||||
assert!(force || finalize.is_none()); // `finalize` implies `force`
|
||||
|
|
@ -442,13 +442,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ctxt,
|
||||
scope_set,
|
||||
parent_scope,
|
||||
// Shadowed bindings don't need to be marked as used or non-speculatively loaded.
|
||||
// Shadowed decls don't need to be marked as used or non-speculatively loaded.
|
||||
if innermost_results.is_empty() { finalize } else { None },
|
||||
force,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
) {
|
||||
Ok(binding) => Ok(binding),
|
||||
Ok(decl) => Ok(decl),
|
||||
// We can break with an error at this step, it means we cannot determine the
|
||||
// resolution right now, but we must block and wait until we can, instead of
|
||||
// considering outer scopes. Although there's no need to do that if we already
|
||||
|
|
@ -459,32 +459,32 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
Err(determinacy) => Err(determinacy.into_value()),
|
||||
};
|
||||
match res {
|
||||
Ok(binding) if sub_namespace_match(binding.macro_kinds(), macro_kind) => {
|
||||
Ok(decl) if sub_namespace_match(decl.macro_kinds(), macro_kind) => {
|
||||
// Below we report various ambiguity errors.
|
||||
// We do not need to report them if we are either in speculative resolution,
|
||||
// or in late resolution when everything is already imported and expanded
|
||||
// and no ambiguities exist.
|
||||
if matches!(finalize, None | Some(Finalize { stage: Stage::Late, .. })) {
|
||||
return ControlFlow::Break(Ok(binding));
|
||||
return ControlFlow::Break(Ok(decl));
|
||||
}
|
||||
|
||||
if let Some(&(innermost_binding, _)) = innermost_results.first() {
|
||||
if let Some(&(innermost_decl, _)) = innermost_results.first() {
|
||||
// Found another solution, if the first one was "weak", report an error.
|
||||
if this.get_mut().maybe_push_ambiguity(
|
||||
orig_ident,
|
||||
ns,
|
||||
scope_set,
|
||||
parent_scope,
|
||||
binding,
|
||||
decl,
|
||||
scope,
|
||||
&innermost_results,
|
||||
) {
|
||||
// No need to search for more potential ambiguities, one is enough.
|
||||
return ControlFlow::Break(Ok(innermost_binding));
|
||||
return ControlFlow::Break(Ok(innermost_decl));
|
||||
}
|
||||
}
|
||||
|
||||
innermost_results.push((binding, scope));
|
||||
innermost_results.push((decl, scope));
|
||||
}
|
||||
Ok(_) | Err(Determinacy::Determined) => {}
|
||||
Err(Determinacy::Undetermined) => determinacy = Determinacy::Undetermined,
|
||||
|
|
@ -501,7 +501,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
|
||||
// Scope visiting walked all the scopes and maybe found something in one of them.
|
||||
match innermost_results.first() {
|
||||
Some(&(binding, ..)) => Ok(binding),
|
||||
Some(&(decl, ..)) => Ok(decl),
|
||||
None => Err(Determinacy::determined(determinacy == Determinacy::Determined || force)),
|
||||
}
|
||||
}
|
||||
|
|
@ -517,16 +517,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope: &ParentScope<'ra>,
|
||||
finalize: Option<Finalize>,
|
||||
force: bool,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
|
||||
let ident = Ident::new(orig_ident.name, orig_ident.span.with_ctxt(ctxt));
|
||||
let ret = match scope {
|
||||
Scope::DeriveHelpers(expn_id) => {
|
||||
if let Some(binding) = self.helper_attrs.get(&expn_id).and_then(|attrs| {
|
||||
attrs.iter().rfind(|(i, _)| ident == *i).map(|(_, binding)| *binding)
|
||||
}) {
|
||||
Ok(binding)
|
||||
if let Some(decl) = self
|
||||
.helper_attrs
|
||||
.get(&expn_id)
|
||||
.and_then(|attrs| attrs.iter().rfind(|(i, _)| ident == *i).map(|(_, d)| *d))
|
||||
{
|
||||
Ok(decl)
|
||||
} else {
|
||||
Err(Determinacy::Determined)
|
||||
}
|
||||
|
|
@ -543,12 +545,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
) {
|
||||
Ok((Some(ext), _)) => {
|
||||
if ext.helper_attrs.contains(&ident.name) {
|
||||
let binding = self.arenas.new_pub_def_decl(
|
||||
let decl = self.arenas.new_pub_def_decl(
|
||||
Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat),
|
||||
derive.span,
|
||||
LocalExpnId::ROOT,
|
||||
);
|
||||
result = Ok(binding);
|
||||
result = Ok(decl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -577,7 +579,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
finalize.map(|f| Finalize { used: Used::Scope, ..f }),
|
||||
)
|
||||
};
|
||||
let binding = self.reborrow().resolve_ident_in_module_non_globs_unadjusted(
|
||||
let decl = self.reborrow().resolve_ident_in_module_non_globs_unadjusted(
|
||||
module,
|
||||
ident,
|
||||
ns,
|
||||
|
|
@ -588,11 +590,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
Shadowing::Restricted
|
||||
},
|
||||
adjusted_finalize,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => {
|
||||
match decl {
|
||||
Ok(decl) => {
|
||||
if let Some(lint_id) = derive_fallback_lint_id {
|
||||
self.get_mut().lint_buffer.buffer_lint(
|
||||
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
|
||||
|
|
@ -605,7 +607,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
},
|
||||
);
|
||||
}
|
||||
Ok(binding)
|
||||
Ok(decl)
|
||||
}
|
||||
Err(ControlFlow::Continue(determinacy)) => Err(determinacy),
|
||||
Err(ControlFlow::Break(determinacy)) => {
|
||||
|
|
@ -638,7 +640,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
Shadowing::Restricted
|
||||
},
|
||||
adjusted_finalize,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
);
|
||||
match binding {
|
||||
|
|
@ -666,18 +668,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
}
|
||||
}
|
||||
Scope::MacroUsePrelude => match self.macro_use_prelude.get(&ident.name).cloned() {
|
||||
Some(binding) => Ok(binding),
|
||||
Some(decl) => Ok(decl),
|
||||
None => Err(Determinacy::determined(
|
||||
self.graph_root.unexpanded_invocations.borrow().is_empty(),
|
||||
)),
|
||||
},
|
||||
Scope::BuiltinAttrs => match self.builtin_attr_decls.get(&ident.name) {
|
||||
Some(binding) => Ok(*binding),
|
||||
Some(decl) => Ok(*decl),
|
||||
None => Err(Determinacy::Determined),
|
||||
},
|
||||
Scope::ExternPreludeItems => {
|
||||
match self.reborrow().extern_prelude_get_item(ident, finalize.is_some()) {
|
||||
Some(binding) => Ok(binding),
|
||||
Some(decl) => Ok(decl),
|
||||
None => Err(Determinacy::determined(
|
||||
self.graph_root.unexpanded_invocations.borrow().is_empty(),
|
||||
)),
|
||||
|
|
@ -685,36 +687,35 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
}
|
||||
Scope::ExternPreludeFlags => {
|
||||
match self.extern_prelude_get_flag(ident, finalize.is_some()) {
|
||||
Some(binding) => Ok(binding),
|
||||
Some(decl) => Ok(decl),
|
||||
None => Err(Determinacy::Determined),
|
||||
}
|
||||
}
|
||||
Scope::ToolPrelude => match self.registered_tool_decls.get(&ident) {
|
||||
Some(binding) => Ok(*binding),
|
||||
Some(decl) => Ok(*decl),
|
||||
None => Err(Determinacy::Determined),
|
||||
},
|
||||
Scope::StdLibPrelude => {
|
||||
let mut result = Err(Determinacy::Determined);
|
||||
if let Some(prelude) = self.prelude
|
||||
&& let Ok(binding) = self.reborrow().resolve_ident_in_scope_set(
|
||||
&& let Ok(decl) = self.reborrow().resolve_ident_in_scope_set(
|
||||
ident,
|
||||
ScopeSet::Module(ns, prelude),
|
||||
parent_scope,
|
||||
None,
|
||||
false,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
&& (matches!(use_prelude, UsePrelude::Yes)
|
||||
|| self.is_builtin_macro(binding.res()))
|
||||
&& (matches!(use_prelude, UsePrelude::Yes) || self.is_builtin_macro(decl.res()))
|
||||
{
|
||||
result = Ok(binding)
|
||||
result = Ok(decl)
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
Scope::BuiltinTypes => match self.builtin_type_decls.get(&ident.name) {
|
||||
Some(binding) => {
|
||||
Some(decl) => {
|
||||
if matches!(ident.name, sym::f16)
|
||||
&& !self.tcx.features().f16()
|
||||
&& !ident.span.allows_unstable(sym::f16)
|
||||
|
|
@ -741,7 +742,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
)
|
||||
.emit();
|
||||
}
|
||||
Ok(*binding)
|
||||
Ok(*decl)
|
||||
}
|
||||
None => Err(Determinacy::Determined),
|
||||
},
|
||||
|
|
@ -756,12 +757,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns: Namespace,
|
||||
scope_set: ScopeSet<'ra>,
|
||||
parent_scope: &ParentScope<'ra>,
|
||||
binding: Decl<'ra>,
|
||||
decl: Decl<'ra>,
|
||||
scope: Scope<'ra>,
|
||||
innermost_results: &[(Decl<'ra>, Scope<'ra>)],
|
||||
) -> bool {
|
||||
let (innermost_binding, innermost_scope) = *innermost_results.first().unwrap();
|
||||
let (res, innermost_res) = (binding.res(), innermost_binding.res());
|
||||
let (innermost_decl, innermost_scope) = innermost_results[0];
|
||||
let (res, innermost_res) = (decl.res(), innermost_decl.res());
|
||||
if res == innermost_res {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -781,7 +782,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
span_bug!(orig_ident.span, "impossible inner resolution kind")
|
||||
} else if matches!(innermost_scope, Scope::MacroRules(_))
|
||||
&& matches!(scope, Scope::ModuleNonGlobs(..) | Scope::ModuleGlobs(..))
|
||||
&& !self.disambiguate_macro_rules_vs_modularized(innermost_binding, binding)
|
||||
&& !self.disambiguate_macro_rules_vs_modularized(innermost_decl, decl)
|
||||
{
|
||||
Some(AmbiguityKind::MacroRulesVsModularized)
|
||||
} else if matches!(scope, Scope::MacroRules(_))
|
||||
|
|
@ -797,13 +798,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
"ambiguous scoped macro resolutions with path-based \
|
||||
scope resolution as first candidate"
|
||||
)
|
||||
} else if innermost_binding.is_glob_import() {
|
||||
} else if innermost_decl.is_glob_import() {
|
||||
Some(AmbiguityKind::GlobVsOuter)
|
||||
} else if !module_only
|
||||
&& innermost_binding.may_appear_after(parent_scope.expansion, binding)
|
||||
{
|
||||
} else if !module_only && innermost_decl.may_appear_after(parent_scope.expansion, decl) {
|
||||
Some(AmbiguityKind::MoreExpandedVsOuter)
|
||||
} else if innermost_binding.expansion != LocalExpnId::ROOT
|
||||
} else if innermost_decl.expansion != LocalExpnId::ROOT
|
||||
&& (!module_only || ns == MacroNS)
|
||||
&& let Scope::ModuleGlobs(m1, _) = scope
|
||||
&& let Scope::ModuleNonGlobs(m2, _) = innermost_scope
|
||||
|
|
@ -822,9 +821,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
// by extern item bindings.
|
||||
// FIXME: Remove with lang team approval.
|
||||
let issue_145575_hack = matches!(scope, Scope::ExternPreludeFlags)
|
||||
&& innermost_results[1..].iter().any(|(b, s)| {
|
||||
matches!(s, Scope::ExternPreludeItems) && *b != innermost_binding
|
||||
});
|
||||
&& innermost_results[1..]
|
||||
.iter()
|
||||
.any(|(b, s)| matches!(s, Scope::ExternPreludeItems) && *b != innermost_decl);
|
||||
// Skip ambiguity errors for nonglob module bindings "overridden"
|
||||
// by glob module bindings in the same module.
|
||||
// FIXME: Remove with lang team approval.
|
||||
|
|
@ -845,8 +844,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
self.ambiguity_errors.push(AmbiguityError {
|
||||
kind,
|
||||
ident: orig_ident,
|
||||
b1: innermost_binding,
|
||||
b2: binding,
|
||||
b1: innermost_decl,
|
||||
b2: decl,
|
||||
scope1: innermost_scope,
|
||||
scope2: scope,
|
||||
warning: false,
|
||||
|
|
@ -878,7 +877,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'ra>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> Result<Decl<'ra>, Determinacy> {
|
||||
let tmp_parent_scope;
|
||||
|
|
@ -904,7 +903,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns,
|
||||
adjusted_parent_scope,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
}
|
||||
|
|
@ -918,7 +917,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'ra>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> Result<Decl<'ra>, Determinacy> {
|
||||
match module {
|
||||
|
|
@ -928,7 +927,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
),
|
||||
ModuleOrUniformRoot::ModuleAndExternPrelude(module) => self.resolve_ident_in_scope_set(
|
||||
|
|
@ -937,7 +936,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
),
|
||||
ModuleOrUniformRoot::ExternPrelude => {
|
||||
|
|
@ -950,7 +949,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
}
|
||||
|
|
@ -973,7 +972,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
}
|
||||
|
|
@ -991,7 +990,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
finalize: Option<Finalize>,
|
||||
// This binding should be ignored during in-module resolution, so that we don't get
|
||||
// "self-confirming" import resolutions during import validation and checking.
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
|
||||
let key = BindingKey::new(ident, ns);
|
||||
|
|
@ -1003,7 +1002,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
.try_borrow_mut_unchecked()
|
||||
.map_err(|_| ControlFlow::Continue(Determined))?;
|
||||
|
||||
let binding = resolution.non_glob_binding.filter(|b| Some(*b) != ignore_binding);
|
||||
let binding = resolution.non_glob_decl.filter(|b| Some(*b) != ignore_decl);
|
||||
|
||||
if let Some(finalize) = finalize {
|
||||
return self.get_mut().finalize_module_binding(
|
||||
|
|
@ -1028,7 +1027,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None,
|
||||
ns,
|
||||
ignore_import,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
parent_scope,
|
||||
) {
|
||||
return Err(ControlFlow::Break(Undetermined));
|
||||
|
|
@ -1052,7 +1051,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope: &ParentScope<'ra>,
|
||||
shadowing: Shadowing,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> Result<Decl<'ra>, ControlFlow<Determinacy, Determinacy>> {
|
||||
let key = BindingKey::new(ident, ns);
|
||||
|
|
@ -1064,7 +1063,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
.try_borrow_mut_unchecked()
|
||||
.map_err(|_| ControlFlow::Continue(Determined))?;
|
||||
|
||||
let binding = resolution.glob_binding.filter(|b| Some(*b) != ignore_binding);
|
||||
let binding = resolution.glob_decl.filter(|b| Some(*b) != ignore_decl);
|
||||
|
||||
if let Some(finalize) = finalize {
|
||||
return self.get_mut().finalize_module_binding(
|
||||
|
|
@ -1084,7 +1083,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
binding,
|
||||
ns,
|
||||
ignore_import,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
parent_scope,
|
||||
) {
|
||||
return Err(ControlFlow::Break(Undetermined));
|
||||
|
|
@ -1154,7 +1153,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
adjusted_parent_scope,
|
||||
None,
|
||||
false,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
);
|
||||
|
||||
|
|
@ -1192,7 +1191,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
if report_private {
|
||||
self.privacy_errors.push(PrivacyError {
|
||||
ident,
|
||||
binding,
|
||||
decl: binding,
|
||||
dedup_span: path_span,
|
||||
outermost_res: None,
|
||||
source: None,
|
||||
|
|
@ -1255,12 +1254,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
binding: Option<Decl<'ra>>,
|
||||
ns: Namespace,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
parent_scope: &ParentScope<'ra>,
|
||||
) -> bool {
|
||||
for single_import in &resolution.single_imports {
|
||||
if let Some(binding) = resolution.non_glob_binding
|
||||
&& let DeclKind::Import { import, .. } = binding.kind
|
||||
if let Some(decl) = resolution.non_glob_decl
|
||||
&& let DeclKind::Import { import, .. } = decl.kind
|
||||
&& import == *single_import
|
||||
{
|
||||
// Single import has already defined the name and we are aware of it,
|
||||
|
|
@ -1273,7 +1272,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
if !self.is_accessible_from(single_import.vis, parent_scope.module) {
|
||||
continue;
|
||||
}
|
||||
if let Some(ignored) = ignore_binding
|
||||
if let Some(ignored) = ignore_decl
|
||||
&& let DeclKind::Import { import, .. } = ignored.kind
|
||||
&& import == *single_import
|
||||
{
|
||||
|
|
@ -1283,13 +1282,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
let Some(module) = single_import.imported_module.get() else {
|
||||
return true;
|
||||
};
|
||||
let ImportKind::Single { source, target, bindings, .. } = &single_import.kind else {
|
||||
let ImportKind::Single { source, target, decls, .. } = &single_import.kind else {
|
||||
unreachable!();
|
||||
};
|
||||
if source != target {
|
||||
if bindings.iter().all(|binding| binding.get().decl().is_none()) {
|
||||
if decls.iter().all(|d| d.get().decl().is_none()) {
|
||||
return true;
|
||||
} else if bindings[ns].get().decl().is_none() && binding.is_some() {
|
||||
} else if decls[ns].get().decl().is_none() && binding.is_some() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1300,7 +1299,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns,
|
||||
&single_import.parent_scope,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
) {
|
||||
Err(Determined) => continue,
|
||||
|
|
@ -1665,7 +1664,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'ra>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
) -> PathResult<'ra> {
|
||||
self.resolve_path_with_ribs(
|
||||
|
|
@ -1675,7 +1674,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None,
|
||||
finalize,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
None,
|
||||
)
|
||||
|
|
@ -1689,7 +1688,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
source: Option<PathSource<'_, '_, '_>>,
|
||||
finalize: Option<Finalize>,
|
||||
ribs: Option<&PerNS<Vec<Rib<'ra>>>>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
ignore_import: Option<Import<'ra>>,
|
||||
diag_metadata: Option<&DiagMetadata<'_>>,
|
||||
) -> PathResult<'ra> {
|
||||
|
|
@ -1816,7 +1815,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
ns,
|
||||
parent_scope,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
} else if let Some(ribs) = ribs
|
||||
|
|
@ -1829,7 +1828,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
&ribs[ns],
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
diag_metadata,
|
||||
) {
|
||||
// we found a locally-imported or available item/module
|
||||
|
|
@ -1851,7 +1850,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
)
|
||||
};
|
||||
|
|
@ -1951,7 +1950,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
opt_ns,
|
||||
parent_scope,
|
||||
ribs,
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
ignore_import,
|
||||
module,
|
||||
segment_idx,
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ pub(crate) enum ImportKind<'ra> {
|
|||
/// `target` in `use prefix::source as target`.
|
||||
/// It will directly use `source` when the format is `use prefix::source`.
|
||||
target: Ident,
|
||||
/// Bindings introduced by the import.
|
||||
bindings: PerNS<CmCell<PendingDecl<'ra>>>,
|
||||
/// Name declarations introduced by the import.
|
||||
decls: PerNS<CmCell<PendingDecl<'ra>>>,
|
||||
/// `true` for `...::{self [as target]}` imports, `false` otherwise.
|
||||
type_ns_only: bool,
|
||||
/// Did this import result from a nested import? ie. `use foo::{bar, baz};`
|
||||
|
|
@ -110,14 +110,14 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use ImportKind::*;
|
||||
match self {
|
||||
Single { source, target, bindings, type_ns_only, nested, id, .. } => f
|
||||
Single { source, target, decls, type_ns_only, nested, id, .. } => f
|
||||
.debug_struct("Single")
|
||||
.field("source", source)
|
||||
.field("target", target)
|
||||
// Ignore the nested bindings to avoid an infinite loop while printing.
|
||||
.field(
|
||||
"bindings",
|
||||
&bindings.clone().map(|b| b.into_inner().decl().map(|_| format_args!(".."))),
|
||||
"decls",
|
||||
&decls.clone().map(|b| b.into_inner().decl().map(|_| format_args!(".."))),
|
||||
)
|
||||
.field("type_ns_only", type_ns_only)
|
||||
.field("nested", nested)
|
||||
|
|
@ -244,16 +244,16 @@ pub(crate) struct NameResolution<'ra> {
|
|||
/// Single imports that may define the name in the namespace.
|
||||
/// Imports are arena-allocated, so it's ok to use pointers as keys.
|
||||
pub single_imports: FxIndexSet<Import<'ra>>,
|
||||
/// The non-glob binding for this name, if it is known to exist.
|
||||
pub non_glob_binding: Option<Decl<'ra>>,
|
||||
/// The glob binding for this name, if it is known to exist.
|
||||
pub glob_binding: Option<Decl<'ra>>,
|
||||
/// The non-glob declaration for this name, if it is known to exist.
|
||||
pub non_glob_decl: Option<Decl<'ra>>,
|
||||
/// The glob declaration for this name, if it is known to exist.
|
||||
pub glob_decl: Option<Decl<'ra>>,
|
||||
}
|
||||
|
||||
impl<'ra> NameResolution<'ra> {
|
||||
/// Returns the binding for the name if it is known or None if it not known.
|
||||
pub(crate) fn binding(&self) -> Option<Decl<'ra>> {
|
||||
self.best_binding().and_then(|binding| {
|
||||
self.best_decl().and_then(|binding| {
|
||||
if !binding.is_glob_import() || self.single_imports.is_empty() {
|
||||
Some(binding)
|
||||
} else {
|
||||
|
|
@ -262,8 +262,8 @@ impl<'ra> NameResolution<'ra> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn best_binding(&self) -> Option<Decl<'ra>> {
|
||||
self.non_glob_binding.or(self.glob_binding)
|
||||
pub(crate) fn best_decl(&self) -> Option<Decl<'ra>> {
|
||||
self.non_glob_decl.or(self.glob_decl)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,16 +296,16 @@ fn pub_use_of_private_extern_crate_hack(import: Import<'_>, decl: Decl<'_>) -> O
|
|||
}
|
||||
|
||||
impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
/// Given a binding and an import that resolves to it,
|
||||
/// return the corresponding binding defined by the import.
|
||||
pub(crate) fn import(&self, binding: Decl<'ra>, import: Import<'ra>) -> Decl<'ra> {
|
||||
/// Given an import and the declaration that it points to,
|
||||
/// create the corresponding import declaration.
|
||||
pub(crate) fn new_import_decl(&self, decl: Decl<'ra>, import: Import<'ra>) -> Decl<'ra> {
|
||||
let import_vis = import.vis.to_def_id();
|
||||
let vis = if binding.vis.is_at_least(import_vis, self.tcx)
|
||||
|| pub_use_of_private_extern_crate_hack(import, binding).is_some()
|
||||
let vis = if decl.vis.is_at_least(import_vis, self.tcx)
|
||||
|| pub_use_of_private_extern_crate_hack(import, decl).is_some()
|
||||
{
|
||||
import_vis
|
||||
} else {
|
||||
binding.vis
|
||||
decl.vis
|
||||
};
|
||||
|
||||
if let ImportKind::Glob { ref max_vis, .. } = import.kind
|
||||
|
|
@ -316,7 +316,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
}
|
||||
|
||||
self.arenas.alloc_decl(DeclData {
|
||||
kind: DeclKind::Import { binding, import },
|
||||
kind: DeclKind::Import { binding: decl, import },
|
||||
ambiguity: None,
|
||||
warn_ambiguity: false,
|
||||
span: import.span,
|
||||
|
|
@ -325,18 +325,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Define the name or return the existing binding if there is a collision.
|
||||
pub(crate) fn try_define_local(
|
||||
/// Attempt to put the declaration with the given name and namespace into the module,
|
||||
/// and return existing declaration if there is a collision.
|
||||
pub(crate) fn try_plant_decl_into_local_module(
|
||||
&mut self,
|
||||
module: Module<'ra>,
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
binding: Decl<'ra>,
|
||||
decl: Decl<'ra>,
|
||||
warn_ambiguity: bool,
|
||||
) -> Result<(), Decl<'ra>> {
|
||||
let res = binding.res();
|
||||
let res = decl.res();
|
||||
self.check_reserved_macro_name(ident, res);
|
||||
self.set_decl_parent_module(binding, module);
|
||||
self.set_decl_parent_module(decl, module);
|
||||
// Even if underscore names cannot be looked up, we still need to add them to modules,
|
||||
// because they can be fetched by glob imports from those modules, and bring traits
|
||||
// into scope both directly and through glob imports.
|
||||
|
|
@ -345,67 +346,66 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
module.underscore_disambiguator.get()
|
||||
});
|
||||
self.update_local_resolution(module, key, warn_ambiguity, |this, resolution| {
|
||||
if let Some(old_binding) = resolution.best_binding() {
|
||||
if res == Res::Err && old_binding.res() != Res::Err {
|
||||
// Do not override real bindings with `Res::Err`s from error recovery.
|
||||
if let Some(old_decl) = resolution.best_decl() {
|
||||
if res == Res::Err && old_decl.res() != Res::Err {
|
||||
// Do not override real declarations with `Res::Err`s from error recovery.
|
||||
return Ok(());
|
||||
}
|
||||
match (old_binding.is_glob_import(), binding.is_glob_import()) {
|
||||
match (old_decl.is_glob_import(), decl.is_glob_import()) {
|
||||
(true, true) => {
|
||||
let (glob_binding, old_glob_binding) = (binding, old_binding);
|
||||
// FIXME: remove `!binding.is_ambiguity_recursive()` after delete the warning ambiguity.
|
||||
if !binding.is_ambiguity_recursive()
|
||||
&& let DeclKind::Import { import: old_import, .. } =
|
||||
old_glob_binding.kind
|
||||
&& let DeclKind::Import { import, .. } = glob_binding.kind
|
||||
let (glob_decl, old_glob_decl) = (decl, old_decl);
|
||||
// FIXME: remove `!decl.is_ambiguity_recursive()` after delete the warning ambiguity.
|
||||
if !decl.is_ambiguity_recursive()
|
||||
&& let DeclKind::Import { import: old_import, .. } = old_glob_decl.kind
|
||||
&& let DeclKind::Import { import, .. } = glob_decl.kind
|
||||
&& old_import == import
|
||||
{
|
||||
// When imported from the same glob-import statement, we should replace
|
||||
// `old_glob_binding` with `glob_binding`, regardless of whether
|
||||
// `old_glob_decl` with `glob_decl`, regardless of whether
|
||||
// they have the same resolution or not.
|
||||
resolution.glob_binding = Some(glob_binding);
|
||||
} else if res != old_glob_binding.res() {
|
||||
resolution.glob_binding = Some(this.new_decl_with_ambiguity(
|
||||
old_glob_binding,
|
||||
glob_binding,
|
||||
resolution.glob_decl = Some(glob_decl);
|
||||
} else if res != old_glob_decl.res() {
|
||||
resolution.glob_decl = Some(this.new_decl_with_ambiguity(
|
||||
old_glob_decl,
|
||||
glob_decl,
|
||||
warn_ambiguity,
|
||||
));
|
||||
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
|
||||
} else if !old_decl.vis.is_at_least(decl.vis, this.tcx) {
|
||||
// We are glob-importing the same item but with greater visibility.
|
||||
resolution.glob_binding = Some(glob_binding);
|
||||
} else if binding.is_ambiguity_recursive() {
|
||||
resolution.glob_binding =
|
||||
Some(this.new_decl_with_warn_ambiguity(glob_binding));
|
||||
resolution.glob_decl = Some(glob_decl);
|
||||
} else if decl.is_ambiguity_recursive() {
|
||||
resolution.glob_decl =
|
||||
Some(this.new_decl_with_warn_ambiguity(glob_decl));
|
||||
}
|
||||
}
|
||||
(old_glob @ true, false) | (old_glob @ false, true) => {
|
||||
let (glob_binding, non_glob_binding) =
|
||||
if old_glob { (old_binding, binding) } else { (binding, old_binding) };
|
||||
resolution.non_glob_binding = Some(non_glob_binding);
|
||||
if let Some(old_glob_binding) = resolution.glob_binding {
|
||||
assert!(old_glob_binding.is_glob_import());
|
||||
if glob_binding.res() != old_glob_binding.res() {
|
||||
resolution.glob_binding = Some(this.new_decl_with_ambiguity(
|
||||
old_glob_binding,
|
||||
glob_binding,
|
||||
let (glob_decl, non_glob_decl) =
|
||||
if old_glob { (old_decl, decl) } else { (decl, old_decl) };
|
||||
resolution.non_glob_decl = Some(non_glob_decl);
|
||||
if let Some(old_glob_decl) = resolution.glob_decl {
|
||||
assert!(old_glob_decl.is_glob_import());
|
||||
if glob_decl.res() != old_glob_decl.res() {
|
||||
resolution.glob_decl = Some(this.new_decl_with_ambiguity(
|
||||
old_glob_decl,
|
||||
glob_decl,
|
||||
false,
|
||||
));
|
||||
} else if !old_glob_binding.vis.is_at_least(binding.vis, this.tcx) {
|
||||
resolution.glob_binding = Some(glob_binding);
|
||||
} else if !old_glob_decl.vis.is_at_least(decl.vis, this.tcx) {
|
||||
resolution.glob_decl = Some(glob_decl);
|
||||
}
|
||||
} else {
|
||||
resolution.glob_binding = Some(glob_binding);
|
||||
resolution.glob_decl = Some(glob_decl);
|
||||
}
|
||||
}
|
||||
(false, false) => {
|
||||
return Err(old_binding);
|
||||
return Err(old_decl);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if binding.is_glob_import() {
|
||||
resolution.glob_binding = Some(binding);
|
||||
if decl.is_glob_import() {
|
||||
resolution.glob_decl = Some(decl);
|
||||
} else {
|
||||
resolution.non_glob_binding = Some(binding);
|
||||
resolution.non_glob_decl = Some(decl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -445,14 +445,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
// during which the resolution might end up getting re-defined via a glob cycle.
|
||||
let (binding, t, warn_ambiguity) = {
|
||||
let resolution = &mut *self.resolution_or_default(module, key).borrow_mut_unchecked();
|
||||
let old_binding = resolution.binding();
|
||||
let old_decl = resolution.binding();
|
||||
|
||||
let t = f(self, resolution);
|
||||
|
||||
if let Some(binding) = resolution.binding()
|
||||
&& old_binding != Some(binding)
|
||||
&& old_decl != Some(binding)
|
||||
{
|
||||
(binding, t, warn_ambiguity || old_binding.is_some())
|
||||
(binding, t, warn_ambiguity || old_decl.is_some())
|
||||
} else {
|
||||
return t;
|
||||
}
|
||||
|
|
@ -471,12 +471,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None => continue,
|
||||
};
|
||||
if self.is_accessible_from(binding.vis, scope) {
|
||||
let imported_binding = self.import(binding, *import);
|
||||
let _ = self.try_define_local(
|
||||
let import_decl = self.new_import_decl(binding, *import);
|
||||
let _ = self.try_plant_decl_into_local_module(
|
||||
import.parent_scope.module,
|
||||
ident.0,
|
||||
key.ns,
|
||||
imported_binding,
|
||||
import_decl,
|
||||
warn_ambiguity,
|
||||
);
|
||||
}
|
||||
|
|
@ -488,16 +488,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
// Define a dummy resolution containing a `Res::Err` as a placeholder for a failed
|
||||
// or indeterminate resolution, also mark such failed imports as used to avoid duplicate diagnostics.
|
||||
fn import_dummy_binding(&mut self, import: Import<'ra>, is_indeterminate: bool) {
|
||||
if let ImportKind::Single { target, ref bindings, .. } = import.kind {
|
||||
if !(is_indeterminate || bindings.iter().all(|binding| binding.get().decl().is_none()))
|
||||
{
|
||||
if let ImportKind::Single { target, ref decls, .. } = import.kind {
|
||||
if !(is_indeterminate || decls.iter().all(|d| d.get().decl().is_none())) {
|
||||
return; // Has resolution, do not create the dummy binding
|
||||
}
|
||||
let dummy_decl = self.dummy_decl;
|
||||
let dummy_decl = self.import(dummy_decl, import);
|
||||
let dummy_decl = self.new_import_decl(dummy_decl, import);
|
||||
self.per_ns(|this, ns| {
|
||||
let module = import.parent_scope.module;
|
||||
let _ = this.try_define_local(module, target, ns, dummy_decl, false);
|
||||
let _ =
|
||||
this.try_plant_decl_into_local_module(module, target, ns, dummy_decl, false);
|
||||
// Don't remove underscores from `single_imports`, they were never added.
|
||||
if target.name != kw::Underscore {
|
||||
let key = BindingKey::new(target, ns);
|
||||
|
|
@ -574,10 +574,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
|
||||
glob_error |= import.is_glob();
|
||||
|
||||
if let ImportKind::Single { source, ref bindings, .. } = import.kind
|
||||
if let ImportKind::Single { source, ref decls, .. } = import.kind
|
||||
&& source.name == kw::SelfLower
|
||||
// Silence `unresolved import` error if E0429 is already emitted
|
||||
&& let PendingDecl::Ready(None) = bindings.value_ns.get()
|
||||
&& let PendingDecl::Ready(None) = decls.value_ns.get()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -631,7 +631,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
for module in &self.local_modules {
|
||||
for (key, resolution) in self.resolutions(*module).borrow().iter() {
|
||||
let resolution = resolution.borrow();
|
||||
let Some(binding) = resolution.best_binding() else { continue };
|
||||
let Some(binding) = resolution.best_decl() else { continue };
|
||||
|
||||
if let DeclKind::Import { import, .. } = binding.kind
|
||||
&& let Some(amb_binding) = binding.ambiguity
|
||||
|
|
@ -651,16 +651,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
if let Some(glob_binding) = resolution.glob_binding
|
||||
&& resolution.non_glob_binding.is_some()
|
||||
if let Some(glob_decl) = resolution.glob_decl
|
||||
&& resolution.non_glob_decl.is_some()
|
||||
{
|
||||
if binding.res() != Res::Err
|
||||
&& glob_binding.res() != Res::Err
|
||||
&& let DeclKind::Import { import: glob_import, .. } = glob_binding.kind
|
||||
&& glob_decl.res() != Res::Err
|
||||
&& let DeclKind::Import { import: glob_import, .. } = glob_decl.kind
|
||||
&& let Some(glob_import_id) = glob_import.id()
|
||||
&& let glob_import_def_id = self.local_def_id(glob_import_id)
|
||||
&& self.effective_visibilities.is_exported(glob_import_def_id)
|
||||
&& glob_binding.vis.is_public()
|
||||
&& glob_decl.vis.is_public()
|
||||
&& !binding.vis.is_public()
|
||||
{
|
||||
let binding_id = match binding.kind {
|
||||
|
|
@ -677,7 +677,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
BuiltinLintDiag::HiddenGlobReexports {
|
||||
name: key.ident.name.to_string(),
|
||||
namespace: key.ns.descr().to_owned(),
|
||||
glob_reexport_span: glob_binding.span,
|
||||
glob_reexport_span: glob_decl.span,
|
||||
private_item_span: binding.span,
|
||||
},
|
||||
);
|
||||
|
|
@ -838,8 +838,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
|
||||
import.imported_module.set_unchecked(Some(module));
|
||||
let (source, target, bindings, type_ns_only) = match import.kind {
|
||||
ImportKind::Single { source, target, ref bindings, type_ns_only, .. } => {
|
||||
(source, target, bindings, type_ns_only)
|
||||
ImportKind::Single { source, target, ref decls, type_ns_only, .. } => {
|
||||
(source, target, decls, type_ns_only)
|
||||
}
|
||||
ImportKind::Glob { .. } => {
|
||||
self.get_mut_unchecked().resolve_glob_import(import);
|
||||
|
|
@ -876,14 +876,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
.emit();
|
||||
}
|
||||
// We need the `target`, `source` can be extracted.
|
||||
let imported_binding = this.import(binding, import);
|
||||
this.get_mut_unchecked().define_binding_local(
|
||||
let import_decl = this.new_import_decl(binding, import);
|
||||
this.get_mut_unchecked().plant_decl_into_local_module(
|
||||
parent,
|
||||
target,
|
||||
ns,
|
||||
imported_binding,
|
||||
import_decl,
|
||||
);
|
||||
PendingDecl::Ready(Some(imported_binding))
|
||||
PendingDecl::Ready(Some(import_decl))
|
||||
}
|
||||
Err(Determinacy::Determined) => {
|
||||
// Don't remove underscores from `single_imports`, they were never added.
|
||||
|
|
@ -917,8 +917,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
/// Optionally returns an unresolved import error. This error is buffered and used to
|
||||
/// consolidate multiple unresolved import errors into a single diagnostic.
|
||||
fn finalize_import(&mut self, import: Import<'ra>) -> Option<UnresolvedImportError> {
|
||||
let ignore_binding = match &import.kind {
|
||||
ImportKind::Single { bindings, .. } => bindings[TypeNS].get().decl(),
|
||||
let ignore_decl = match &import.kind {
|
||||
ImportKind::Single { decls, .. } => decls[TypeNS].get().decl(),
|
||||
_ => None,
|
||||
};
|
||||
let ambiguity_errors_len =
|
||||
|
|
@ -934,7 +934,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None,
|
||||
&import.parent_scope,
|
||||
Some(finalize),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
Some(import),
|
||||
);
|
||||
|
||||
|
|
@ -1037,8 +1037,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
};
|
||||
|
||||
let (ident, target, bindings, type_ns_only, import_id) = match import.kind {
|
||||
ImportKind::Single { source, target, ref bindings, type_ns_only, id, .. } => {
|
||||
(source, target, bindings, type_ns_only, id)
|
||||
ImportKind::Single { source, target, ref decls, type_ns_only, id, .. } => {
|
||||
(source, target, decls, type_ns_only, id)
|
||||
}
|
||||
ImportKind::Glob { ref max_vis, id } => {
|
||||
if import.module_path.len() <= 1 {
|
||||
|
|
@ -1094,7 +1094,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None,
|
||||
&import.parent_scope,
|
||||
Some(finalize),
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
None,
|
||||
) {
|
||||
let res = module.res().map(|r| (r, ident));
|
||||
|
|
@ -1197,7 +1197,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
} // Never suggest the same name
|
||||
|
||||
let resolution = resolution.borrow();
|
||||
if let Some(name_binding) = resolution.best_binding() {
|
||||
if let Some(name_binding) = resolution.best_decl() {
|
||||
match name_binding.kind {
|
||||
DeclKind::Import { binding, .. } => {
|
||||
match binding.kind {
|
||||
|
|
@ -1383,7 +1383,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
|
||||
pub(crate) fn check_for_redundant_imports(&mut self, import: Import<'ra>) -> bool {
|
||||
// This function is only called for single imports.
|
||||
let ImportKind::Single { source, target, ref bindings, id, .. } = import.kind else {
|
||||
let ImportKind::Single { source, target, ref decls, id, .. } = import.kind else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
|
|
@ -1410,7 +1410,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
let mut is_redundant = true;
|
||||
let mut redundant_span = PerNS { value_ns: None, type_ns: None, macro_ns: None };
|
||||
self.per_ns(|this, ns| {
|
||||
let binding = bindings[ns].get().decl().map(|b| b.import_source());
|
||||
let binding = decls[ns].get().decl().map(|b| b.import_source());
|
||||
if is_redundant && let Some(binding) = binding {
|
||||
if binding.res() == Res::Err {
|
||||
return;
|
||||
|
|
@ -1422,7 +1422,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
&import.parent_scope,
|
||||
None,
|
||||
false,
|
||||
bindings[ns].get().decl(),
|
||||
decls[ns].get().decl(),
|
||||
None,
|
||||
) {
|
||||
Ok(other_binding) => {
|
||||
|
|
@ -1497,16 +1497,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
None => continue,
|
||||
};
|
||||
if self.is_accessible_from(binding.vis, scope) {
|
||||
let imported_binding = self.import(binding, import);
|
||||
let import_decl = self.new_import_decl(binding, import);
|
||||
let warn_ambiguity = self
|
||||
.resolution(import.parent_scope.module, key)
|
||||
.and_then(|r| r.binding())
|
||||
.is_some_and(|binding| binding.warn_ambiguity_recursive());
|
||||
let _ = self.try_define_local(
|
||||
let _ = self.try_plant_decl_into_local_module(
|
||||
import.parent_scope.module,
|
||||
key.ident.0,
|
||||
key.ns,
|
||||
imported_binding,
|
||||
import_decl,
|
||||
warn_ambiguity,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -677,7 +677,7 @@ impl MaybeExported<'_> {
|
|||
/// Used for recording UnnecessaryQualification.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct UnnecessaryQualification<'ra> {
|
||||
pub binding: LateDecl<'ra>,
|
||||
pub decl: LateDecl<'ra>,
|
||||
pub node_id: NodeId,
|
||||
pub path_span: Span,
|
||||
pub removal_span: Span,
|
||||
|
|
@ -1489,7 +1489,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
ident: Ident,
|
||||
ns: Namespace,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<Decl<'ra>>,
|
||||
ignore_decl: Option<Decl<'ra>>,
|
||||
) -> Option<LateDecl<'ra>> {
|
||||
self.r.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
|
|
@ -1497,7 +1497,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
&self.parent_scope,
|
||||
finalize,
|
||||
&self.ribs[ns],
|
||||
ignore_binding,
|
||||
ignore_decl,
|
||||
Some(&self.diag_metadata),
|
||||
)
|
||||
}
|
||||
|
|
@ -3630,9 +3630,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
};
|
||||
ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
|
||||
let key = BindingKey::new(ident, ns);
|
||||
let mut binding = self.r.resolution(module, key).and_then(|r| r.best_binding());
|
||||
debug!(?binding);
|
||||
if binding.is_none() {
|
||||
let mut decl = self.r.resolution(module, key).and_then(|r| r.best_decl());
|
||||
debug!(?decl);
|
||||
if decl.is_none() {
|
||||
// We could not find the trait item in the correct namespace.
|
||||
// Check the other namespace to report an error.
|
||||
let ns = match ns {
|
||||
|
|
@ -3641,8 +3641,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
_ => ns,
|
||||
};
|
||||
let key = BindingKey::new(ident, ns);
|
||||
binding = self.r.resolution(module, key).and_then(|r| r.best_binding());
|
||||
debug!(?binding);
|
||||
decl = self.r.resolution(module, key).and_then(|r| r.best_decl());
|
||||
debug!(?decl);
|
||||
}
|
||||
|
||||
let feed_visibility = |this: &mut Self, def_id| {
|
||||
|
|
@ -3659,7 +3659,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
this.r.feed_visibility(this.r.feed(id), vis);
|
||||
};
|
||||
|
||||
let Some(binding) = binding else {
|
||||
let Some(decl) = decl else {
|
||||
// We could not find the method: report an error.
|
||||
let candidate = self.find_similarly_named_assoc_item(ident.name, kind);
|
||||
let path = &self.current_trait_ref.as_ref().unwrap().1.path;
|
||||
|
|
@ -3669,7 +3669,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
return;
|
||||
};
|
||||
|
||||
let res = binding.res();
|
||||
let res = decl.res();
|
||||
let Res::Def(def_kind, id_in_trait) = res else { bug!() };
|
||||
feed_visibility(self, id_in_trait);
|
||||
|
||||
|
|
@ -3680,7 +3680,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
ResolutionError::TraitImplDuplicate {
|
||||
name: ident,
|
||||
old_span: *entry.get(),
|
||||
trait_item_span: binding.span,
|
||||
trait_item_span: decl.span,
|
||||
},
|
||||
);
|
||||
return;
|
||||
|
|
@ -3720,7 +3720,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
kind,
|
||||
code,
|
||||
trait_path,
|
||||
trait_item_span: binding.span,
|
||||
trait_item_span: decl.span,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -5356,9 +5356,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
(res == binding.res()).then_some((seg, binding))
|
||||
});
|
||||
|
||||
if let Some((seg, binding)) = unqualified {
|
||||
if let Some((seg, decl)) = unqualified {
|
||||
self.r.potentially_unnecessary_qualifications.push(UnnecessaryQualification {
|
||||
binding,
|
||||
decl,
|
||||
node_id: finalize.node_id,
|
||||
path_span: finalize.path_span,
|
||||
removal_span: path[0].ident.span.until(seg.ident.span),
|
||||
|
|
|
|||
|
|
@ -891,10 +891,8 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
fn lookup_doc_alias_name(&mut self, path: &[Segment], ns: Namespace) -> Option<(DefId, Ident)> {
|
||||
let find_doc_alias_name = |r: &mut Resolver<'ra, '_>, m: Module<'ra>, item_name: Symbol| {
|
||||
for resolution in r.resolutions(m).borrow().values() {
|
||||
let Some(did) = resolution
|
||||
.borrow()
|
||||
.best_binding()
|
||||
.and_then(|binding| binding.res().opt_def_id())
|
||||
let Some(did) =
|
||||
resolution.borrow().best_decl().and_then(|binding| binding.res().opt_def_id())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
|
@ -1589,19 +1587,17 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) =
|
||||
self.resolve_path(mod_path, None, None, *source)
|
||||
{
|
||||
let targets: Vec<_> = self
|
||||
.r
|
||||
.resolutions(module)
|
||||
.borrow()
|
||||
.iter()
|
||||
.filter_map(|(key, resolution)| {
|
||||
resolution
|
||||
.borrow()
|
||||
.best_binding()
|
||||
.map(|binding| binding.res())
|
||||
.and_then(|res| if filter_fn(res) { Some((*key, res)) } else { None })
|
||||
})
|
||||
.collect();
|
||||
let targets: Vec<_> =
|
||||
self.r
|
||||
.resolutions(module)
|
||||
.borrow()
|
||||
.iter()
|
||||
.filter_map(|(key, resolution)| {
|
||||
resolution.borrow().best_decl().map(|binding| binding.res()).and_then(
|
||||
|res| if filter_fn(res) { Some((*key, res)) } else { None },
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
if let [target] = targets.as_slice() {
|
||||
return Some(TypoSuggestion::single_item_from_ident(
|
||||
target.0.ident.0,
|
||||
|
|
@ -2486,9 +2482,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
.resolutions(*module)
|
||||
.borrow()
|
||||
.iter()
|
||||
.filter_map(|(key, res)| {
|
||||
res.borrow().best_binding().map(|binding| (key, binding.res()))
|
||||
})
|
||||
.filter_map(|(key, res)| res.borrow().best_decl().map(|binding| (key, binding.res())))
|
||||
.filter(|(_, res)| match (kind, res) {
|
||||
(AssocItemKind::Const(..), Res::Def(DefKind::AssocConst, _)) => true,
|
||||
(AssocItemKind::Fn(_), Res::Def(DefKind::AssocFn, _)) => true,
|
||||
|
|
|
|||
|
|
@ -692,8 +692,8 @@ impl<'ra> Module<'ra> {
|
|||
mut f: impl FnMut(&R, Macros20NormalizedIdent, Namespace, Decl<'ra>),
|
||||
) {
|
||||
for (key, name_resolution) in resolver.as_ref().resolutions(self).borrow().iter() {
|
||||
if let Some(binding) = name_resolution.borrow().best_binding() {
|
||||
f(resolver, key.ident, key.ns, binding);
|
||||
if let Some(decl) = name_resolution.borrow().best_decl() {
|
||||
f(resolver, key.ident, key.ns, decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -704,8 +704,8 @@ impl<'ra> Module<'ra> {
|
|||
mut f: impl FnMut(&mut R, Macros20NormalizedIdent, Namespace, Decl<'ra>),
|
||||
) {
|
||||
for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() {
|
||||
if let Some(binding) = name_resolution.borrow().best_binding() {
|
||||
f(resolver, key.ident, key.ns, binding);
|
||||
if let Some(decl) = name_resolution.borrow().best_decl() {
|
||||
f(resolver, key.ident, key.ns, decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -842,7 +842,7 @@ enum DeclKind<'ra> {
|
|||
}
|
||||
|
||||
impl<'ra> DeclKind<'ra> {
|
||||
/// Is this a name binding of an import?
|
||||
/// Is this an import declaration?
|
||||
fn is_import(&self) -> bool {
|
||||
matches!(*self, DeclKind::Import { .. })
|
||||
}
|
||||
|
|
@ -851,7 +851,7 @@ impl<'ra> DeclKind<'ra> {
|
|||
#[derive(Debug)]
|
||||
struct PrivacyError<'ra> {
|
||||
ident: Ident,
|
||||
binding: Decl<'ra>,
|
||||
decl: Decl<'ra>,
|
||||
dedup_span: Span,
|
||||
outermost_res: Option<(Res, Ident)>,
|
||||
parent_scope: ParentScope<'ra>,
|
||||
|
|
@ -2047,15 +2047,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
fn record_use_inner(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
used_binding: Decl<'ra>,
|
||||
used_decl: Decl<'ra>,
|
||||
used: Used,
|
||||
warn_ambiguity: bool,
|
||||
) {
|
||||
if let Some(b2) = used_binding.ambiguity {
|
||||
if let Some(b2) = used_decl.ambiguity {
|
||||
let ambiguity_error = AmbiguityError {
|
||||
kind: AmbiguityKind::GlobVsGlob,
|
||||
ident,
|
||||
b1: used_binding,
|
||||
b1: used_decl,
|
||||
b2,
|
||||
scope1: Scope::ModuleGlobs(self.empty_module, None),
|
||||
scope2: Scope::ModuleGlobs(self.empty_module, None),
|
||||
|
|
@ -2066,7 +2066,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
self.ambiguity_errors.push(ambiguity_error);
|
||||
}
|
||||
}
|
||||
if let DeclKind::Import { import, binding } = used_binding.kind {
|
||||
if let DeclKind::Import { import, binding } = used_decl.kind {
|
||||
if let ImportKind::MacroUse { warn_private: true } = import.kind {
|
||||
// Do not report the lint if the macro name resolves in stdlib prelude
|
||||
// even without the problematic `macro_use` import.
|
||||
|
|
@ -2096,7 +2096,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
// but not introduce it, as used if they are accessed from lexical scope.
|
||||
if used == Used::Scope
|
||||
&& let Some(entry) = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident))
|
||||
&& entry.item_decl == Some((used_binding, false))
|
||||
&& entry.item_decl == Some((used_decl, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ use crate::{
|
|||
type Res = def::Res<NodeId>;
|
||||
|
||||
/// Name declaration produced by a `macro_rules` item definition.
|
||||
/// Not modularized, can shadow previous `macro_rules` bindings, etc.
|
||||
/// Not modularized, can shadow previous `macro_rules` definitions, etc.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct MacroRulesDecl<'ra> {
|
||||
pub(crate) decl: Decl<'ra>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue