Skip to content

Commit d500de6

Browse files
address review
1 parent 55792dc commit d500de6

File tree

8 files changed

+24
-22
lines changed

8 files changed

+24
-22
lines changed

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl Resolver<'_, '_> {
511511
for (_key, resolution) in self.resolutions(*module).borrow().iter() {
512512
let resolution = resolution.borrow();
513513

514-
if let Some(binding) = resolution.late_binding()
514+
if let Some(binding) = resolution.best_binding()
515515
&& let NameBindingKind::Import { import, .. } = binding.kind
516516
&& let ImportKind::Single { id, .. } = import.kind
517517
{

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14401440
|(key, name_resolution)| {
14411441
if key.ns == TypeNS
14421442
&& key.ident == ident
1443-
&& let Some(binding) = name_resolution.borrow().late_binding()
1443+
&& let Some(binding) = name_resolution.borrow().best_binding()
14441444
{
14451445
match binding.res() {
14461446
// No disambiguation needed if the identically named item we
@@ -1494,7 +1494,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14941494
return None;
14951495
};
14961496
for (_, resolution) in this.resolutions(m).borrow().iter() {
1497-
let Some(binding) = resolution.borrow().late_binding() else {
1497+
let Some(binding) = resolution.borrow().best_binding() else {
14981498
continue;
14991499
};
15001500
let Res::Def(DefKind::Macro(MacroKind::Derive | MacroKind::Attr), def_id) =

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
883883
return self.finalize_module_binding(
884884
ident,
885885
binding,
886-
resolution.glob_binding,
886+
if resolution.non_glob_binding.is_some() { resolution.glob_binding } else { None },
887887
parent_scope,
888888
finalize,
889889
shadowing,

compiler/rustc_resolve/src/imports.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub(crate) struct NameResolution<'ra> {
251251
impl<'ra> NameResolution<'ra> {
252252
/// Returns the binding for the name if it is known or None if it not known.
253253
pub(crate) fn binding(&self) -> Option<NameBinding<'ra>> {
254-
self.late_binding().and_then(|binding| {
254+
self.best_binding().and_then(|binding| {
255255
if !binding.is_glob_import() || self.single_imports.is_empty() {
256256
Some(binding)
257257
} else {
@@ -260,7 +260,7 @@ impl<'ra> NameResolution<'ra> {
260260
})
261261
}
262262

263-
pub(crate) fn late_binding(&self) -> Option<NameBinding<'ra>> {
263+
pub(crate) fn best_binding(&self) -> Option<NameBinding<'ra>> {
264264
self.non_glob_binding.or(self.glob_binding)
265265
}
266266
}
@@ -343,7 +343,7 @@ 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.late_binding() {
346+
if let Some(old_binding) = resolution.best_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(());
@@ -394,16 +394,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
394394
resolution.non_glob_binding = Some(non_glob_binding);
395395
}
396396

397-
if let Some(old_glob) = resolution.glob_binding {
398-
assert!(old_glob.is_glob_import());
399-
if glob_binding.res() != old_glob.res() {
397+
if let Some(old_glob_binding) = resolution.glob_binding {
398+
assert!(old_glob_binding.is_glob_import());
399+
if glob_binding.res() != old_glob_binding.res() {
400400
resolution.glob_binding = Some(this.new_ambiguity_binding(
401401
AmbiguityKind::GlobVsGlob,
402-
old_glob,
402+
old_glob_binding,
403403
glob_binding,
404404
false,
405405
));
406-
} else if !old_glob.vis.is_at_least(binding.vis, this.tcx) {
406+
} else if !old_glob_binding.vis.is_at_least(binding.vis, this.tcx) {
407407
resolution.glob_binding = Some(glob_binding);
408408
}
409409
} else {
@@ -639,7 +639,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
639639
for (key, resolution) in self.resolutions(*module).borrow().iter() {
640640
let resolution = resolution.borrow();
641641

642-
let Some(binding) = resolution.late_binding() else { continue };
642+
let Some(binding) = resolution.best_binding() else { continue };
643643

644644
if let NameBindingKind::Import { import, .. } = binding.kind
645645
&& let Some((amb_binding, _)) = binding.ambiguity
@@ -659,7 +659,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
659659
);
660660
}
661661

662-
if let Some(glob_binding) = resolution.glob_binding {
662+
if let Some(glob_binding) = resolution.glob_binding
663+
&& resolution.non_glob_binding.is_some()
664+
{
663665
if binding.res() != Res::Err
664666
&& glob_binding.res() != Res::Err
665667
&& let NameBindingKind::Import { import: glob_import, .. } =
@@ -1191,7 +1193,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11911193
} // Never suggest the same name
11921194
match *resolution.borrow() {
11931195
ref resolution
1194-
if let Some(name_binding) = resolution.late_binding() =>
1196+
if let Some(name_binding) = resolution.best_binding() =>
11951197
{
11961198
match name_binding.kind {
11971199
NameBindingKind::Import { binding, .. } => {

compiler/rustc_resolve/src/late.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,7 +3438,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34383438
ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
34393439
let key = BindingKey::new(ident, ns);
34403440
let mut binding =
3441-
self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.late_binding());
3441+
self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.best_binding());
34423442
debug!(?binding);
34433443
if binding.is_none() {
34443444
// We could not find the trait item in the correct namespace.
@@ -3450,7 +3450,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34503450
};
34513451
let key = BindingKey::new(ident, ns);
34523452
binding =
3453-
self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.late_binding());
3453+
self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.best_binding());
34543454
debug!(?binding);
34553455
}
34563456

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
882882
for resolution in r.resolutions(m).borrow().values() {
883883
let Some(did) = resolution
884884
.borrow()
885-
.late_binding()
885+
.best_binding()
886886
.and_then(|binding| binding.res().opt_def_id())
887887
else {
888888
continue;
@@ -1471,7 +1471,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14711471
.filter_map(|(key, resolution)| {
14721472
resolution
14731473
.borrow()
1474-
.late_binding()
1474+
.best_binding()
14751475
.map(|binding| binding.res())
14761476
.and_then(|res| if filter_fn(res) { Some((key, res)) } else { None })
14771477
})
@@ -2309,7 +2309,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
23092309
.borrow()
23102310
.iter()
23112311
.filter_map(|(key, res)| {
2312-
res.borrow().late_binding().map(|binding| (key, binding.res()))
2312+
res.borrow().best_binding().map(|binding| (key, binding.res()))
23132313
})
23142314
.filter(|(_, res)| match (kind, res) {
23152315
(AssocItemKind::Const(..), Res::Def(DefKind::AssocConst, _)) => true,

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<'ra> Module<'ra> {
641641
F: FnMut(&mut R, Ident, Namespace, NameBinding<'ra>),
642642
{
643643
for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() {
644-
if let Some(binding) = name_resolution.borrow().late_binding() {
644+
if let Some(binding) = name_resolution.borrow().best_binding() {
645645
f(resolver, key.ident, key.ns, binding);
646646
}
647647
}

tests/ui/imports/ambiguous-4-extern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
macro_rules! m {
77
() => {
8-
pub fn id() {}
8+
pub fn id() {}
99
};
1010
}
1111

0 commit comments

Comments
 (0)