about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/imports.rs
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2025-07-19 09:30:39 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2025-07-19 09:30:39 +0000
commit9613ce02c393104ba7ebd4655d004e5f6da3db18 (patch)
tree4d0783dd5712fb37e2f9c2089a25d20a2cab6f56 /compiler/rustc_resolve/src/imports.rs
parent1079c5edb2bd837e5c4cf8c7db2892db359a3862 (diff)
downloadrust-9613ce02c393104ba7ebd4655d004e5f6da3db18.tar.gz
rust-9613ce02c393104ba7ebd4655d004e5f6da3db18.zip
Revert "resolve: Make disambiguators for underscore bindings module-local"
This reverts commit 998df3a3e851908afd05c3318f16d99849af5c55.
Diffstat (limited to 'compiler/rustc_resolve/src/imports.rs')
-rw-r--r--compiler/rustc_resolve/src/imports.rs38
1 files changed, 13 insertions, 25 deletions
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs
index b4c15ed1ca7..0a4c25b0eb0 100644
--- a/compiler/rustc_resolve/src/imports.rs
+++ b/compiler/rustc_resolve/src/imports.rs
@@ -25,7 +25,7 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
 use smallvec::SmallVec;
 use tracing::debug;
 
-use crate::Namespace::{self, *};
+use crate::Namespace::*;
 use crate::diagnostics::{DiagMode, Suggestion, import_candidates};
 use crate::errors::{
     CannotBeReexportedCratePublic, CannotBeReexportedCratePublicNS, CannotBeReexportedPrivate,
@@ -338,20 +338,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
     pub(crate) fn try_define(
         &mut self,
         module: Module<'ra>,
-        ident: Ident,
-        ns: Namespace,
+        key: BindingKey,
         binding: NameBinding<'ra>,
         warn_ambiguity: bool,
     ) -> Result<(), NameBinding<'ra>> {
         let res = binding.res();
-        self.check_reserved_macro_name(ident, res);
+        self.check_reserved_macro_name(key.ident, res);
         self.set_binding_parent_module(binding, 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.
-        let key = BindingKey::new_disambiguated(ident, ns, || {
-            (module.0.0.lazy_resolutions.borrow().len() + 1).try_into().unwrap()
-        });
         self.update_resolution(module, key, warn_ambiguity, |this, resolution| {
             if let Some(old_binding) = resolution.best_binding() {
                 if res == Res::Err && old_binding.res() != Res::Err {
@@ -390,7 +383,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                     (old_glob @ true, false) | (old_glob @ false, true) => {
                         let (glob_binding, non_glob_binding) =
                             if old_glob { (old_binding, binding) } else { (binding, old_binding) };
-                        if ns == MacroNS
+                        if key.ns == MacroNS
                             && non_glob_binding.expansion != LocalExpnId::ROOT
                             && glob_binding.res() != non_glob_binding.res()
                         {
@@ -496,10 +489,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
             };
             if self.is_accessible_from(binding.vis, scope) {
                 let imported_binding = self.import(binding, *import);
+                let key = BindingKey { ident, ..key };
                 let _ = self.try_define(
                     import.parent_scope.module,
-                    ident,
-                    key.ns,
+                    key,
                     imported_binding,
                     warn_ambiguity,
                 );
@@ -521,15 +514,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
             let dummy_binding = self.dummy_binding;
             let dummy_binding = self.import(dummy_binding, import);
             self.per_ns(|this, ns| {
-                let module = import.parent_scope.module;
-                let _ = this.try_define(module, target, ns, dummy_binding, false);
-                // Don't remove underscores from `single_imports`, they were never added.
-                if target.name != kw::Underscore {
-                    let key = BindingKey::new(target, ns);
-                    this.update_resolution(module, key, false, |_, resolution| {
-                        resolution.single_imports.swap_remove(&import);
-                    })
-                }
+                let key = BindingKey::new(target, ns);
+                let _ = this.try_define(import.parent_scope.module, key, dummy_binding, false);
+                this.update_resolution(import.parent_scope.module, key, false, |_, resolution| {
+                    resolution.single_imports.swap_remove(&import);
+                })
             });
             self.record_use(target, dummy_binding, Used::Other);
         } else if import.imported_module.get().is_none() {
@@ -906,7 +895,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                         PendingBinding::Ready(Some(imported_binding))
                     }
                     Err(Determinacy::Determined) => {
-                        // Don't remove underscores from `single_imports`, they were never added.
+                        // Don't update the resolution for underscores, because it was never added.
                         if target.name != kw::Underscore {
                             let key = BindingKey::new(target, ns);
                             this.update_resolution(parent, key, false, |_, resolution| {
@@ -1521,8 +1510,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                     .is_some_and(|binding| binding.warn_ambiguity_recursive());
                 let _ = self.try_define(
                     import.parent_scope.module,
-                    key.ident,
-                    key.ns,
+                    key,
                     imported_binding,
                     warn_ambiguity,
                 );