@@ -2307,7 +2307,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23072307
23082308 self . mention_default_field_values ( source, ident, & mut err) ;
23092309
2310- if let Some ( ( this_res, outer_ident) ) = outermost_res {
2310+ let shown_candidates = if let Some ( ( this_res, outer_ident) ) = outermost_res {
23112311 let mut import_suggestions = self . lookup_import_candidates (
23122312 outer_ident,
23132313 this_res. ns ( ) . unwrap_or ( Namespace :: TypeNS ) ,
@@ -2338,7 +2338,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23382338 } ;
23392339 err. subdiagnostic ( label) ;
23402340 }
2341- }
2341+ !point_to_def
2342+ } else {
2343+ false
2344+ } ;
23422345
23432346 let mut non_exhaustive = None ;
23442347 // If an ADT is foreign and marked as `non_exhaustive`, then that's
@@ -2476,8 +2479,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24762479 // 2) the use isn't nested, otherwise `dedup_span` is one ident in `{...}`.
24772480 //
24782481 // See issue #156060.
2479- let can_replace_use =
2480- !single_nested && !outermost_res. is_some_and ( |( _, outer) | outer. span != ident. span ) ;
2482+ let can_replace_use = !shown_candidates
2483+ && !single_nested
2484+ && !outermost_res. is_some_and ( |( _, outer) | outer. span != ident. span ) ;
24812485 if can_replace_use {
24822486 // We prioritize shorter paths, non-core imports and direct imports over the
24832487 // alternatives.
0 commit comments