summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_resolve/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_resolve/src/lib.rs')
-rw-r--r--compiler/rustc_resolve/src/lib.rs38
1 files changed, 32 insertions, 6 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index da3d86a47..76e54e60d 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -18,6 +18,7 @@
#![recursion_limit = "256"]
#![allow(rustdoc::private_intra_doc_links)]
#![allow(rustc::potential_query_instability)]
+#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use]
extern crate tracing;
@@ -658,6 +659,7 @@ impl<'a> fmt::Debug for Module<'a> {
struct NameBindingData<'a> {
kind: NameBindingKind<'a>,
ambiguity: Option<(NameBinding<'a>, AmbiguityKind)>,
+ warn_ambiguity: bool,
expansion: LocalExpnId,
span: Span,
vis: ty::Visibility<DefId>,
@@ -767,6 +769,7 @@ struct AmbiguityError<'a> {
b2: NameBinding<'a>,
misc1: AmbiguityErrorMisc,
misc2: AmbiguityErrorMisc,
+ warning: bool,
}
impl<'a> NameBindingData<'a> {
@@ -794,6 +797,14 @@ impl<'a> NameBindingData<'a> {
}
}
+ fn is_warn_ambiguity(&self) -> bool {
+ self.warn_ambiguity
+ || match self.kind {
+ NameBindingKind::Import { binding, .. } => binding.is_warn_ambiguity(),
+ _ => false,
+ }
+ }
+
fn is_possibly_imported_variant(&self) -> bool {
match self.kind {
NameBindingKind::Import { binding, .. } => binding.is_possibly_imported_variant(),
@@ -1158,7 +1169,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
}
fn local_def_id(&self, node: NodeId) -> LocalDefId {
- self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
+ self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
}
/// Adds a definition with a parent definition.
@@ -1271,7 +1282,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let registered_tools = tcx.registered_tools(());
- let features = tcx.sess.features_untracked();
+ let features = tcx.features();
let mut resolver = Resolver {
tcx,
@@ -1322,6 +1333,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
dummy_binding: arenas.alloc_name_binding(NameBindingData {
kind: NameBindingKind::Res(Res::Err),
ambiguity: None,
+ warn_ambiguity: false,
expansion: LocalExpnId::ROOT,
span: DUMMY_SP,
vis: ty::Visibility::Public,
@@ -1685,6 +1697,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
fn record_use(&mut self, ident: Ident, used_binding: NameBinding<'a>, is_lexical_scope: bool) {
+ self.record_use_inner(ident, used_binding, is_lexical_scope, used_binding.warn_ambiguity);
+ }
+
+ fn record_use_inner(
+ &mut self,
+ ident: Ident,
+ used_binding: NameBinding<'a>,
+ is_lexical_scope: bool,
+ warn_ambiguity: bool,
+ ) {
if let Some((b2, kind)) = used_binding.ambiguity {
let ambiguity_error = AmbiguityError {
kind,
@@ -1693,9 +1715,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
b2,
misc1: AmbiguityErrorMisc::None,
misc2: AmbiguityErrorMisc::None,
+ warning: warn_ambiguity,
};
if !self.matches_previous_ambiguity_error(&ambiguity_error) {
- // avoid duplicated span information to be emitt out
+ // avoid duplicated span information to be emit out
self.ambiguity_errors.push(ambiguity_error);
}
}
@@ -1715,7 +1738,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
self.used_imports.insert(id);
}
self.add_to_glob_map(import, ident);
- self.record_use(ident, binding, false);
+ self.record_use_inner(ident, binding, false, warn_ambiguity || binding.warn_ambiguity);
}
}
@@ -1812,7 +1835,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fn record_partial_res(&mut self, node_id: NodeId, resolution: PartialRes) {
debug!("(recording res) recording {:?} for {}", resolution, node_id);
if let Some(prev_res) = self.partial_res_map.insert(node_id, resolution) {
- panic!("path resolved multiple times ({:?} before, {:?} now)", prev_res, resolution);
+ panic!("path resolved multiple times ({prev_res:?} before, {resolution:?} now)");
}
}
@@ -1871,7 +1894,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} else {
let crate_id = if finalize {
let Some(crate_id) =
- self.crate_loader(|c| c.process_path_extern(ident.name, ident.span)) else { return Some(self.dummy_binding); };
+ self.crate_loader(|c| c.process_path_extern(ident.name, ident.span))
+ else {
+ return Some(self.dummy_binding);
+ };
crate_id
} else {
self.crate_loader(|c| c.maybe_process_path_extern(ident.name))?