about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-11-14 10:20:45 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-14 11:35:27 +1100
commit66cc7d6a05f2fadbe100e12ebc65d511fa690aea (patch)
treec1b7a2d1246d96e8fdd58eedb99421e2bc196ef0 /compiler
parent6e0e9edbe034b8ce764f91abb5c12b7871e09e9c (diff)
downloadrust-66cc7d6a05f2fadbe100e12ebc65d511fa690aea.tar.gz
rust-66cc7d6a05f2fadbe100e12ebc65d511fa690aea.zip
Replace the `restricted_shadowing` boolean argument with an enum.
It makes the code clearer.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_resolve/src/ident.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs
index b8e07ef5402..ad825d7813d 100644
--- a/compiler/rustc_resolve/src/ident.rs
+++ b/compiler/rustc_resolve/src/ident.rs
@@ -38,6 +38,12 @@ impl From<UsePrelude> for bool {
     }
 }
 
+#[derive(Debug, PartialEq)]
+enum Shadowing {
+    Restricted,
+    Unrestricted,
+}
+
 impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
     /// A generic scope visitor.
     /// Visits scopes in order to resolve some identifier in them or perform other actions.
@@ -349,7 +355,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                 ident,
                 ns,
                 parent_scope,
-                false,
+                Shadowing::Unrestricted,
                 finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
                 ignore_binding,
                 None,
@@ -521,7 +527,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                             ident,
                             ns,
                             adjusted_parent_scope,
-                            !matches!(scope_set, ScopeSet::Late(..)),
+                            if matches!(scope_set, ScopeSet::Late(..)) {
+                                Shadowing::Unrestricted
+                            } else {
+                                Shadowing::Restricted
+                            },
                             finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
                             ignore_binding,
                             ignore_import,
@@ -590,7 +600,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                                 ident,
                                 ns,
                                 parent_scope,
-                                false,
+                                Shadowing::Unrestricted,
                                 None,
                                 ignore_binding,
                                 ignore_import,
@@ -786,7 +796,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
             ident,
             ns,
             adjusted_parent_scope,
-            false,
+            Shadowing::Unrestricted,
             finalize,
             ignore_binding,
             ignore_import,
@@ -802,7 +812,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
         ident: Ident,
         ns: Namespace,
         parent_scope: &ParentScope<'ra>,
-        restricted_shadowing: bool,
+        shadowing: Shadowing,
         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.
@@ -812,7 +822,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
         let module = match module {
             ModuleOrUniformRoot::Module(module) => module,
             ModuleOrUniformRoot::CrateRootAndExternPrelude => {
-                assert!(!restricted_shadowing);
+                assert_eq!(shadowing, Shadowing::Unrestricted);
                 let binding = self.early_resolve_ident_in_lexical_scope(
                     ident,
                     ScopeSet::AbsolutePath(ns),
@@ -825,7 +835,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                 return binding.map_err(|determinacy| (determinacy, Weak::No));
             }
             ModuleOrUniformRoot::ExternPrelude => {
-                assert!(!restricted_shadowing);
+                assert_eq!(shadowing, Shadowing::Unrestricted);
                 return if ns != TypeNS {
                     Err((Determined, Weak::No))
                 } else if let Some(binding) = self.extern_prelude_get(ident, finalize.is_some()) {
@@ -838,7 +848,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                 };
             }
             ModuleOrUniformRoot::CurrentScope => {
-                assert!(!restricted_shadowing);
+                assert_eq!(shadowing, Shadowing::Unrestricted);
                 if ns == TypeNS {
                     if ident.name == kw::Crate || ident.name == kw::DollarCrate {
                         let module = self.resolve_crate_root(ident);
@@ -897,7 +907,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
 
             // Forbid expanded shadowing to avoid time travel.
             if let Some(shadowed_glob) = resolution.shadowed_glob
-                && restricted_shadowing
+                && shadowing == Shadowing::Restricted
                 && binding.expansion != LocalExpnId::ROOT
                 && binding.res() != shadowed_glob.res()
             {
@@ -912,7 +922,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                 });
             }
 
-            if !restricted_shadowing
+            if shadowing == Shadowing::Unrestricted
                 && binding.expansion != LocalExpnId::ROOT
                 && let NameBindingKind::Import { import, .. } = binding.kind
                 && matches!(import.kind, ImportKind::MacroExport)
@@ -1024,7 +1034,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
         // and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
         // shadowing is enabled, see `macro_expanded_macro_export_errors`).
         if let Some(binding) = binding {
-            if binding.determined() || ns == MacroNS || restricted_shadowing {
+            if binding.determined() || ns == MacroNS || shadowing == Shadowing::Restricted {
                 return check_usable(self, binding);
             } else {
                 return Err((Undetermined, Weak::No));
@@ -1076,7 +1086,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                 ident,
                 ns,
                 adjusted_parent_scope,
-                false,
+                Shadowing::Unrestricted,
                 None,
                 ignore_binding,
                 ignore_import,