@@ -33,12 +33,12 @@ type Res = def::Res<ast::NodeId>;
33
33
crate type Suggestion = ( Vec < ( Span , String ) > , String , Applicability ) ;
34
34
35
35
crate struct TypoSuggestion {
36
- pub candidate : Symbol ,
36
+ pub candidate : Ident ,
37
37
pub res : Res ,
38
38
}
39
39
40
40
impl TypoSuggestion {
41
- crate fn from_res ( candidate : Symbol , res : Res ) -> TypoSuggestion {
41
+ crate fn from_res ( candidate : Ident , res : Res ) -> TypoSuggestion {
42
42
TypoSuggestion { candidate, res }
43
43
}
44
44
}
@@ -107,7 +107,7 @@ impl<'a> Resolver<'a> {
107
107
if let Some ( binding) = resolution. borrow ( ) . binding {
108
108
let res = binding. res ( ) ;
109
109
if filter_fn ( res) {
110
- names. push ( TypoSuggestion :: from_res ( key. ident . name , res) ) ;
110
+ names. push ( TypoSuggestion :: from_res ( key. ident , res) ) ;
111
111
}
112
112
}
113
113
}
@@ -509,7 +509,7 @@ impl<'a> Resolver<'a> {
509
509
. get ( & expn_id)
510
510
. into_iter ( )
511
511
. flatten ( )
512
- . map ( |ident| TypoSuggestion :: from_res ( ident. name , res) ) ,
512
+ . map ( |ident| TypoSuggestion :: from_res ( * ident, res) ) ,
513
513
) ;
514
514
}
515
515
}
@@ -525,11 +525,9 @@ impl<'a> Resolver<'a> {
525
525
false ,
526
526
false ,
527
527
) {
528
- suggestions. extend (
529
- ext. helper_attrs
530
- . iter ( )
531
- . map ( |name| TypoSuggestion :: from_res ( * name, res) ) ,
532
- ) ;
528
+ suggestions. extend ( ext. helper_attrs . iter ( ) . map ( |name| {
529
+ TypoSuggestion :: from_res ( Ident :: new ( * name, derive. span ) , res)
530
+ } ) ) ;
533
531
}
534
532
}
535
533
}
@@ -538,8 +536,7 @@ impl<'a> Resolver<'a> {
538
536
if let LegacyScope :: Binding ( legacy_binding) = legacy_scope {
539
537
let res = legacy_binding. binding . res ( ) ;
540
538
if filter_fn ( res) {
541
- suggestions
542
- . push ( TypoSuggestion :: from_res ( legacy_binding. ident . name , res) )
539
+ suggestions. push ( TypoSuggestion :: from_res ( legacy_binding. ident , res) )
543
540
}
544
541
}
545
542
}
@@ -557,40 +554,40 @@ impl<'a> Resolver<'a> {
557
554
suggestions. extend (
558
555
this. registered_attrs
559
556
. iter ( )
560
- . map ( |ident| TypoSuggestion :: from_res ( ident. name , res) ) ,
557
+ . map ( |ident| TypoSuggestion :: from_res ( * ident, res) ) ,
561
558
) ;
562
559
}
563
560
}
564
561
Scope :: MacroUsePrelude => {
565
562
suggestions. extend ( this. macro_use_prelude . iter ( ) . filter_map (
566
563
|( name, binding) | {
567
564
let res = binding. res ( ) ;
568
- filter_fn ( res) . then_some ( TypoSuggestion :: from_res ( * name, res) )
565
+ let span = binding. span ;
566
+ filter_fn ( res)
567
+ . then_some ( TypoSuggestion :: from_res ( Ident :: new ( * name, span) , res) )
569
568
} ,
570
569
) ) ;
571
570
}
572
571
Scope :: BuiltinAttrs => {
573
572
let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Builtin ) ;
574
573
if filter_fn ( res) {
575
- suggestions. extend (
576
- BUILTIN_ATTRIBUTES
577
- . iter ( )
578
- . map ( |( name, ..) | TypoSuggestion :: from_res ( * name, res) ) ,
579
- ) ;
574
+ suggestions. extend ( BUILTIN_ATTRIBUTES . iter ( ) . map ( |( name, ..) | {
575
+ TypoSuggestion :: from_res ( Ident :: with_dummy_span ( * name) , res)
576
+ } ) ) ;
580
577
}
581
578
}
582
579
Scope :: ExternPrelude => {
583
580
suggestions. extend ( this. extern_prelude . iter ( ) . filter_map ( |( ident, _) | {
584
581
let res = Res :: Def ( DefKind :: Mod , DefId :: local ( CRATE_DEF_INDEX ) ) ;
585
- filter_fn ( res) . then_some ( TypoSuggestion :: from_res ( ident. name , res) )
582
+ filter_fn ( res) . then_some ( TypoSuggestion :: from_res ( * ident, res) )
586
583
} ) ) ;
587
584
}
588
585
Scope :: ToolPrelude => {
589
586
let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ;
590
587
suggestions. extend (
591
588
this. registered_tools
592
589
. iter ( )
593
- . map ( |ident| TypoSuggestion :: from_res ( ident. name , res) ) ,
590
+ . map ( |ident| TypoSuggestion :: from_res ( * ident, res) ) ,
594
591
) ;
595
592
}
596
593
Scope :: StdLibPrelude => {
@@ -608,7 +605,8 @@ impl<'a> Resolver<'a> {
608
605
let primitive_types = & this. primitive_type_table . primitive_types ;
609
606
suggestions. extend ( primitive_types. iter ( ) . flat_map ( |( name, prim_ty) | {
610
607
let res = Res :: PrimTy ( * prim_ty) ;
611
- filter_fn ( res) . then_some ( TypoSuggestion :: from_res ( * name, res) )
608
+ filter_fn ( res)
609
+ . then_some ( TypoSuggestion :: from_res ( Ident :: with_dummy_span ( * name) , res) )
612
610
} ) )
613
611
}
614
612
}
@@ -620,12 +618,12 @@ impl<'a> Resolver<'a> {
620
618
suggestions. sort_by_cached_key ( |suggestion| suggestion. candidate . as_str ( ) ) ;
621
619
622
620
match find_best_match_for_name (
623
- suggestions. iter ( ) . map ( |suggestion| & suggestion. candidate ) ,
621
+ suggestions. iter ( ) . map ( |suggestion| & suggestion. candidate . name ) ,
624
622
& ident. as_str ( ) ,
625
623
None ,
626
624
) {
627
625
Some ( found) if found != ident. name => {
628
- suggestions. into_iter ( ) . find ( |suggestion| suggestion. candidate == found)
626
+ suggestions. into_iter ( ) . find ( |suggestion| suggestion. candidate . name == found)
629
627
}
630
628
_ => None ,
631
629
}
@@ -805,7 +803,7 @@ impl<'a> Resolver<'a> {
805
803
) -> bool {
806
804
if let Some ( suggestion) = suggestion {
807
805
// We shouldn't suggest underscore.
808
- if suggestion. candidate == kw:: Underscore {
806
+ if suggestion. candidate . name == kw:: Underscore {
809
807
return false ;
810
808
}
811
809
@@ -814,12 +812,6 @@ impl<'a> Resolver<'a> {
814
812
suggestion. res. article( ) ,
815
813
suggestion. res. descr( )
816
814
) ;
817
- err. span_suggestion (
818
- span,
819
- & msg,
820
- suggestion. candidate . to_string ( ) ,
821
- Applicability :: MaybeIncorrect ,
822
- ) ;
823
815
let def_span = suggestion. res . opt_def_id ( ) . and_then ( |def_id| match def_id. krate {
824
816
LOCAL_CRATE => self . definitions . opt_span ( def_id) ,
825
817
_ => Some (
@@ -828,16 +820,24 @@ impl<'a> Resolver<'a> {
828
820
. def_span ( self . cstore ( ) . get_span_untracked ( def_id, self . session ) ) ,
829
821
) ,
830
822
} ) ;
823
+ let candidate = def_span
824
+ . as_ref ( )
825
+ . map ( |span| Ident :: new ( suggestion. candidate . name , * span) )
826
+ . unwrap_or ( suggestion. candidate ) ;
827
+
828
+ err. span_suggestion ( span, & msg, candidate. to_string ( ) , Applicability :: MaybeIncorrect ) ;
829
+
831
830
if let Some ( span) = def_span {
832
831
err. span_label (
833
832
span,
834
833
& format ! (
835
834
"similarly named {} `{}` defined here" ,
836
835
suggestion. res. descr( ) ,
837
- suggestion . candidate. as_str ( ) ,
836
+ candidate. to_string ( ) ,
838
837
) ,
839
838
) ;
840
839
}
840
+
841
841
return true ;
842
842
}
843
843
false
0 commit comments