Skip to content

Commit 276b946

Browse files
petrochenkovcjgillot
authored andcommitted
Handle unusable_binding more compactly.
1 parent b796d92 commit 276b946

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

compiler/rustc_resolve/src/ident.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -902,27 +902,24 @@ impl<'a> Resolver<'a> {
902902
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
903903

904904
if let Some(path_span) = finalize {
905-
let Some(mut binding) = resolution.binding else {
906-
return Err((Determined, Weak::No));
907-
};
908-
909905
// If the primary binding is unusable, search further and return the shadowed glob
910906
// binding if it exists. What we really want here is having two separate scopes in
911907
// a module - one for non-globs and one for globs, but until that's done use this
912908
// hack to avoid inconsistent resolution ICEs during import validation.
913-
if let Some(unusable_binding) = unusable_binding
914-
&& ptr::eq(binding, unusable_binding)
915-
{
916-
let Some(shadowed) = resolution.shadowed_glob else {
917-
return Err((Determined, Weak::No));
918-
};
919-
920-
if ptr::eq(shadowed, unusable_binding) {
921-
return Err((Determined, Weak::No));
922-
}
923-
924-
binding = shadowed;
925-
}
909+
let binding = [resolution.binding, resolution.shadowed_glob]
910+
.into_iter()
911+
.filter_map(|binding| match (binding, unusable_binding) {
912+
(Some(binding), Some(unusable_binding))
913+
if ptr::eq(binding, unusable_binding) =>
914+
{
915+
None
916+
}
917+
_ => binding,
918+
})
919+
.next();
920+
let Some(binding) = binding else {
921+
return Err((Determined, Weak::No));
922+
};
926923

927924
if !self.is_accessible_from(binding.vis, parent_scope.module) {
928925
if last_import_segment {

0 commit comments

Comments
 (0)