summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_resolve/src/ident.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_resolve/src/ident.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_resolve/src/ident.rs')
-rw-r--r--compiler/rustc_resolve/src/ident.rs55
1 files changed, 29 insertions, 26 deletions
diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs
index 52f0b65fa..5a56d7b99 100644
--- a/compiler/rustc_resolve/src/ident.rs
+++ b/compiler/rustc_resolve/src/ident.rs
@@ -17,7 +17,7 @@ use crate::late::{
ConstantHasGenerics, ConstantItemKind, HasGenericParams, PathSource, Rib, RibKind,
};
use crate::macros::{sub_namespace_match, MacroRulesScope};
-use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize};
+use crate::{errors, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize};
use crate::{Import, ImportKind, LexicalScopeBinding, Module, ModuleKind, ModuleOrUniformRoot};
use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError, Res};
use crate::{ResolutionError, Resolver, Scope, ScopeSet, Segment, ToNameBinding, Weak};
@@ -389,7 +389,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}
- assert!(force || !finalize.is_some()); // `finalize` implies `force`
+ assert!(force || finalize.is_none()); // `finalize` implies `force`
// Make sure `self`, `super` etc produce an error when passed to here.
if orig_ident.is_path_segment_keyword() {
@@ -869,17 +869,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let resolution =
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
- if let Some(Finalize { path_span, report_private, .. }) = finalize {
- // If the primary binding is unusable, search further and return the shadowed glob
- // binding if it exists. What we really want here is having two separate scopes in
- // a module - one for non-globs and one for globs, but until that's done use this
- // hack to avoid inconsistent resolution ICEs during import validation.
- let binding = [resolution.binding, resolution.shadowed_glob].into_iter().find_map(
- |binding| match (binding, ignore_binding) {
+ // If the primary binding is unusable, search further and return the shadowed glob
+ // binding if it exists. What we really want here is having two separate scopes in
+ // a module - one for non-globs and one for globs, but until that's done use this
+ // hack to avoid inconsistent resolution ICEs during import validation.
+ let binding =
+ [resolution.binding, resolution.shadowed_glob].into_iter().find_map(|binding| {
+ match (binding, ignore_binding) {
(Some(binding), Some(ignored)) if ptr::eq(binding, ignored) => None,
_ => binding,
- },
- );
+ }
+ });
+
+ if let Some(Finalize { path_span, report_private, .. }) = finalize {
let Some(binding) = binding else {
return Err((Determined, Weak::No));
};
@@ -927,15 +929,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
- if let Some(ignored) = ignore_binding && ptr::eq(binding, ignored) {
- return Err((Determined, Weak::No));
- }
let usable = this.is_accessible_from(binding.vis, parent_scope.module);
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
};
// Items and single imports are not shadowable, if we have one, then it's determined.
- if let Some(binding) = resolution.binding {
+ if let Some(binding) = binding {
if !binding.is_glob_import() {
return check_usable(self, binding);
}
@@ -952,6 +951,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if !self.is_accessible_from(import_vis, parent_scope.module) {
continue;
}
+ if let Some(ignored) = ignore_binding &&
+ let NameBindingKind::Import { import, .. } = ignored.kind &&
+ ptr::eq(import, &**single_import) {
+ // Ignore not just the binding itself, but if it has a shadowed_glob,
+ // ignore that, too, because this loop is supposed to only process
+ // named imports.
+ continue;
+ }
let Some(module) = single_import.imported_module.get() else {
return Err((Undetermined, Weak::No));
};
@@ -989,7 +996,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
let unexpanded_macros = !module.unexpanded_invocations.borrow().is_empty();
- if let Some(binding) = resolution.binding {
+ if let Some(binding) = binding {
if !unexpanded_macros || ns == MacroNS || restricted_shadowing {
return check_usable(self, binding);
} else {
@@ -1357,7 +1364,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
};
- let is_last = i == path.len() - 1;
+ let is_last = i + 1 == path.len();
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
let name = ident.name;
@@ -1494,16 +1501,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if let Some(next_module) = binding.module() {
module = Some(ModuleOrUniformRoot::Module(next_module));
record_segment_res(self, res);
- } else if res == Res::ToolMod && i + 1 != path.len() {
+ } else if res == Res::ToolMod && !is_last && opt_ns.is_some() {
if binding.is_import() {
- self.tcx
- .sess
- .struct_span_err(
- ident.span,
- "cannot use a tool module through an import",
- )
- .span_note(binding.span, "the tool module imported here")
- .emit();
+ self.tcx.sess.emit_err(errors::ToolModuleImported {
+ span: ident.span,
+ import: binding.span,
+ });
}
let res = Res::NonMacroAttr(NonMacroAttrKind::Tool);
return PathResult::NonModule(PartialRes::new(res));