@@ -58,16 +58,32 @@ pub(crate) enum SuggestionTarget {
5858#[ derive( Debug ) ]
5959pub ( crate ) struct TypoSuggestion {
6060 pub candidate : Symbol ,
61+ /// The source location where the name is defined; None if the name is not defined
62+ /// in source e.g. primitives
63+ pub span : Option < Span > ,
6164 pub res : Res ,
6265 pub target : SuggestionTarget ,
6366}
6467
6568impl TypoSuggestion {
66- pub ( crate ) fn typo_from_res ( candidate : Symbol , res : Res ) -> TypoSuggestion {
67- Self { candidate, res, target : SuggestionTarget :: SimilarlyNamed }
69+ pub ( crate ) fn typo_from_ident ( ident : Ident , res : Res ) -> TypoSuggestion {
70+ Self {
71+ candidate : ident. name ,
72+ span : Some ( ident. span ) ,
73+ res,
74+ target : SuggestionTarget :: SimilarlyNamed ,
75+ }
76+ }
77+ pub ( crate ) fn typo_from_name ( candidate : Symbol , res : Res ) -> TypoSuggestion {
78+ Self { candidate, span : None , res, target : SuggestionTarget :: SimilarlyNamed }
6879 }
69- pub ( crate ) fn single_item_from_res ( candidate : Symbol , res : Res ) -> TypoSuggestion {
70- Self { candidate, res, target : SuggestionTarget :: SingleItem }
80+ pub ( crate ) fn single_item_from_ident ( ident : Ident , res : Res ) -> TypoSuggestion {
81+ Self {
82+ candidate : ident. name ,
83+ span : Some ( ident. span ) ,
84+ res,
85+ target : SuggestionTarget :: SingleItem ,
86+ }
7187 }
7288}
7389
@@ -490,7 +506,7 @@ impl<'a> Resolver<'a> {
490506 if let Some ( binding) = resolution. borrow ( ) . binding {
491507 let res = binding. res ( ) ;
492508 if filter_fn ( res) && ctxt. map_or ( true , |ctxt| ctxt == key. ident . span . ctxt ( ) ) {
493- names. push ( TypoSuggestion :: typo_from_res ( key. ident . name , res) ) ;
509+ names. push ( TypoSuggestion :: typo_from_ident ( key. ident , res) ) ;
494510 }
495511 }
496512 }
@@ -1145,7 +1161,7 @@ impl<'a> Resolver<'a> {
11451161 . get ( & expn_id)
11461162 . into_iter ( )
11471163 . flatten ( )
1148- . map ( |ident| TypoSuggestion :: typo_from_res ( ident. name , res) ) ,
1164+ . map ( |ident| TypoSuggestion :: typo_from_ident ( * ident, res) ) ,
11491165 ) ;
11501166 }
11511167 }
@@ -1164,7 +1180,7 @@ impl<'a> Resolver<'a> {
11641180 suggestions. extend (
11651181 ext. helper_attrs
11661182 . iter ( )
1167- . map ( |name| TypoSuggestion :: typo_from_res ( * name, res) ) ,
1183+ . map ( |name| TypoSuggestion :: typo_from_name ( * name, res) ) ,
11681184 ) ;
11691185 }
11701186 }
@@ -1174,8 +1190,8 @@ impl<'a> Resolver<'a> {
11741190 if let MacroRulesScope :: Binding ( macro_rules_binding) = macro_rules_scope. get ( ) {
11751191 let res = macro_rules_binding. binding . res ( ) ;
11761192 if filter_fn ( res) {
1177- suggestions. push ( TypoSuggestion :: typo_from_res (
1178- macro_rules_binding. ident . name ,
1193+ suggestions. push ( TypoSuggestion :: typo_from_ident (
1194+ macro_rules_binding. ident ,
11791195 res,
11801196 ) )
11811197 }
@@ -1193,7 +1209,7 @@ impl<'a> Resolver<'a> {
11931209 suggestions. extend ( this. macro_use_prelude . iter ( ) . filter_map (
11941210 |( name, binding) | {
11951211 let res = binding. res ( ) ;
1196- filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_res ( * name, res) )
1212+ filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_name ( * name, res) )
11971213 } ,
11981214 ) ) ;
11991215 }
@@ -1203,22 +1219,22 @@ impl<'a> Resolver<'a> {
12031219 suggestions. extend (
12041220 BUILTIN_ATTRIBUTES
12051221 . iter ( )
1206- . map ( |attr| TypoSuggestion :: typo_from_res ( attr. name , res) ) ,
1222+ . map ( |attr| TypoSuggestion :: typo_from_name ( attr. name , res) ) ,
12071223 ) ;
12081224 }
12091225 }
12101226 Scope :: ExternPrelude => {
12111227 suggestions. extend ( this. extern_prelude . iter ( ) . filter_map ( |( ident, _) | {
12121228 let res = Res :: Def ( DefKind :: Mod , CRATE_DEF_ID . to_def_id ( ) ) ;
1213- filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_res ( ident. name , res) )
1229+ filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_ident ( * ident, res) )
12141230 } ) ) ;
12151231 }
12161232 Scope :: ToolPrelude => {
12171233 let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ;
12181234 suggestions. extend (
12191235 this. registered_tools
12201236 . iter ( )
1221- . map ( |ident| TypoSuggestion :: typo_from_res ( ident. name , res) ) ,
1237+ . map ( |ident| TypoSuggestion :: typo_from_ident ( * ident, res) ) ,
12221238 ) ;
12231239 }
12241240 Scope :: StdLibPrelude => {
@@ -1235,7 +1251,8 @@ impl<'a> Resolver<'a> {
12351251 Scope :: BuiltinTypes => {
12361252 suggestions. extend ( PrimTy :: ALL . iter ( ) . filter_map ( |prim_ty| {
12371253 let res = Res :: PrimTy ( * prim_ty) ;
1238- filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_res ( prim_ty. name ( ) , res) )
1254+ filter_fn ( res)
1255+ . then_some ( TypoSuggestion :: typo_from_name ( prim_ty. name ( ) , res) )
12391256 } ) )
12401257 }
12411258 }
0 commit comments