diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-04-12 20:18:08 +0300 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-04-12 22:07:15 +0200 |
| commit | 276b94601025152a2cf5668a53a96fae94f37731 (patch) | |
| tree | 61e9768978d0f6ac252fe14b7bd688d69fc7615c | |
| parent | b796d92da3a24326a4bd50a95f765331edef780b (diff) | |
| download | rust-276b94601025152a2cf5668a53a96fae94f37731.tar.gz rust-276b94601025152a2cf5668a53a96fae94f37731.zip | |
Handle `unusable_binding` more compactly.
| -rw-r--r-- | compiler/rustc_resolve/src/ident.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index b6cb960b517..25ab3f7dacf 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -902,27 +902,24 @@ impl<'a> Resolver<'a> { self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports. if let Some(path_span) = finalize { - let Some(mut binding) = resolution.binding else { - return Err((Determined, Weak::No)); - }; - // 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. - if let Some(unusable_binding) = unusable_binding - && ptr::eq(binding, unusable_binding) - { - let Some(shadowed) = resolution.shadowed_glob else { - return Err((Determined, Weak::No)); - }; - - if ptr::eq(shadowed, unusable_binding) { - return Err((Determined, Weak::No)); - } - - binding = shadowed; - } + let binding = [resolution.binding, resolution.shadowed_glob] + .into_iter() + .filter_map(|binding| match (binding, unusable_binding) { + (Some(binding), Some(unusable_binding)) + if ptr::eq(binding, unusable_binding) => + { + None + } + _ => binding, + }) + .next(); + let Some(binding) = binding else { + return Err((Determined, Weak::No)); + }; if !self.is_accessible_from(binding.vis, parent_scope.module) { if last_import_segment { |
