@@ -47,6 +47,7 @@ impl TypoSuggestion {
47
47
/// A free importable items suggested in case of resolution failure.
48
48
crate struct ImportSuggestion {
49
49
pub did : Option < DefId > ,
50
+ pub descr : & ' static str ,
50
51
pub path : Path ,
51
52
}
52
53
@@ -652,7 +653,7 @@ impl<'a> Resolver<'a> {
652
653
Res :: Def ( DefKind :: Ctor ( ..) , did) => this. parent ( did) ,
653
654
_ => res. opt_def_id ( ) ,
654
655
} ;
655
- candidates. push ( ImportSuggestion { did, path } ) ;
656
+ candidates. push ( ImportSuggestion { did, descr : res . descr ( ) , path } ) ;
656
657
}
657
658
}
658
659
}
@@ -1445,29 +1446,31 @@ fn find_span_immediately_after_crate_name(
1445
1446
crate fn show_candidates (
1446
1447
err : & mut DiagnosticBuilder < ' _ > ,
1447
1448
// This is `None` if all placement locations are inside expansions
1448
- span : Option < Span > ,
1449
+ use_placement_span : Option < Span > ,
1449
1450
candidates : & [ ImportSuggestion ] ,
1450
1451
better : bool ,
1451
1452
found_use : bool ,
1452
1453
) {
1453
1454
if candidates. is_empty ( ) {
1454
1455
return ;
1455
1456
}
1457
+
1456
1458
// we want consistent results across executions, but candidates are produced
1457
1459
// by iterating through a hash map, so make sure they are ordered:
1458
1460
let mut path_strings: Vec < _ > =
1459
1461
candidates. iter ( ) . map ( |c| path_names_to_string ( & c. path ) ) . collect ( ) ;
1460
1462
path_strings. sort ( ) ;
1461
1463
path_strings. dedup ( ) ;
1462
1464
1463
- let better = if better { "better " } else { "" } ;
1464
- let msg_diff = match path_strings . len ( ) {
1465
- 1 => " is found in another module, you can import it" ,
1466
- _ => "s are found in other modules, you can import them" ,
1465
+ let ( determiner , kind ) = if candidates . len ( ) == 1 {
1466
+ ( "this" , candidates [ 0 ] . descr )
1467
+ } else {
1468
+ ( "one of these" , "items" )
1467
1469
} ;
1468
- let msg = format ! ( "possible {}candidate{} into scope" , better, msg_diff) ;
1470
+ let instead = if better { " instead" } else { "" } ;
1471
+ let msg = format ! ( "consider importing {} {}{}" , determiner, kind, instead) ;
1469
1472
1470
- if let Some ( span) = span {
1473
+ if let Some ( span) = use_placement_span {
1471
1474
for candidate in & mut path_strings {
1472
1475
// produce an additional newline to separate the new use statement
1473
1476
// from the directly following item.
0 commit comments