Skip to content

Commit 55792dc

Browse files
correct assignment of bindings
1 parent fe08e57 commit 55792dc

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -343,66 +343,67 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
343343
self.check_reserved_macro_name(key.ident, res);
344344
self.set_binding_parent_module(binding, module);
345345
self.update_resolution(module, key, warn_ambiguity, |this, resolution| {
346-
if let Some(old_binding) = resolution.non_glob_binding {
346+
if let Some(old_binding) = resolution.late_binding() {
347347
if res == Res::Err && old_binding.res() != Res::Err {
348348
// Do not override real bindings with `Res::Err`s from error recovery.
349349
return Ok(());
350350
}
351351
match (old_binding.is_glob_import(), binding.is_glob_import()) {
352352
(true, true) => {
353+
let (glob_binding, old_glob_binding) = (binding, old_binding);
353354
// FIXME: remove `!binding.is_ambiguity_recursive()` after delete the warning ambiguity.
354355
if !binding.is_ambiguity_recursive()
355356
&& let NameBindingKind::Import { import: old_import, .. } =
356-
old_binding.kind
357-
&& let NameBindingKind::Import { import, .. } = binding.kind
357+
old_glob_binding.kind
358+
&& let NameBindingKind::Import { import, .. } = glob_binding.kind
358359
&& old_import == import
359360
{
360-
// We should replace the `old_binding` with `binding` regardless
361-
// of whether they has same resolution or not when they are
362-
// imported from the same glob-import statement.
363-
resolution.non_glob_binding = Some(binding);
364-
} else if res != old_binding.res() {
365-
resolution.non_glob_binding = Some(this.new_ambiguity_binding(
361+
// When imported from the same glob-import statement, we should replace
362+
// `old_glob_binding` with `glob_binding`, regardless of whether
363+
// they have the same resolution or not.
364+
resolution.glob_binding = Some(glob_binding);
365+
} else if res != old_glob_binding.res() {
366+
resolution.glob_binding = Some(this.new_ambiguity_binding(
366367
AmbiguityKind::GlobVsGlob,
367-
old_binding,
368-
binding,
368+
old_glob_binding,
369+
glob_binding,
369370
warn_ambiguity,
370371
));
371372
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
372373
// We are glob-importing the same item but with greater visibility.
373-
resolution.non_glob_binding = Some(binding);
374+
resolution.glob_binding = Some(glob_binding);
374375
} else if binding.is_ambiguity_recursive() {
375-
resolution.non_glob_binding =
376-
Some(this.new_warn_ambiguity_binding(binding));
376+
resolution.glob_binding =
377+
Some(this.new_warn_ambiguity_binding(glob_binding));
377378
}
378379
}
379380
(old_glob @ true, false) | (old_glob @ false, true) => {
380-
let (glob_binding, nonglob_binding) =
381+
let (glob_binding, non_glob_binding) =
381382
if old_glob { (old_binding, binding) } else { (binding, old_binding) };
382383
if key.ns == MacroNS
383-
&& nonglob_binding.expansion != LocalExpnId::ROOT
384-
&& glob_binding.res() != nonglob_binding.res()
384+
&& non_glob_binding.expansion != LocalExpnId::ROOT
385+
&& glob_binding.res() != non_glob_binding.res()
385386
{
386387
resolution.non_glob_binding = Some(this.new_ambiguity_binding(
387388
AmbiguityKind::GlobVsExpanded,
388-
nonglob_binding,
389+
non_glob_binding,
389390
glob_binding,
390391
false,
391392
));
392393
} else {
393-
resolution.non_glob_binding = Some(nonglob_binding);
394+
resolution.non_glob_binding = Some(non_glob_binding);
394395
}
395396

396-
if let Some(old_shadowed_glob) = resolution.glob_binding {
397-
assert!(old_shadowed_glob.is_glob_import());
398-
if glob_binding.res() != old_shadowed_glob.res() {
397+
if let Some(old_glob) = resolution.glob_binding {
398+
assert!(old_glob.is_glob_import());
399+
if glob_binding.res() != old_glob.res() {
399400
resolution.glob_binding = Some(this.new_ambiguity_binding(
400401
AmbiguityKind::GlobVsGlob,
401-
old_shadowed_glob,
402+
old_glob,
402403
glob_binding,
403404
false,
404405
));
405-
} else if !old_shadowed_glob.vis.is_at_least(binding.vis, this.tcx) {
406+
} else if !old_glob.vis.is_at_least(binding.vis, this.tcx) {
406407
resolution.glob_binding = Some(glob_binding);
407408
}
408409
} else {
@@ -414,7 +415,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
414415
}
415416
}
416417
} else {
417-
resolution.non_glob_binding = Some(binding);
418+
if binding.is_glob_import() {
419+
resolution.glob_binding = Some(binding);
420+
} else {
421+
resolution.non_glob_binding = Some(binding);
422+
}
418423
}
419424

420425
Ok(())

0 commit comments

Comments
 (0)