@@ -58,16 +58,32 @@ pub(crate) enum SuggestionTarget {
58
58
#[ derive( Debug ) ]
59
59
pub ( crate ) struct TypoSuggestion {
60
60
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 > ,
61
64
pub res : Res ,
62
65
pub target : SuggestionTarget ,
63
66
}
64
67
65
68
impl 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 }
68
79
}
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
+ }
71
87
}
72
88
}
73
89
@@ -490,7 +506,7 @@ impl<'a> Resolver<'a> {
490
506
if let Some ( binding) = resolution. borrow ( ) . binding {
491
507
let res = binding. res ( ) ;
492
508
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) ) ;
494
510
}
495
511
}
496
512
}
@@ -1145,7 +1161,7 @@ impl<'a> Resolver<'a> {
1145
1161
. get ( & expn_id)
1146
1162
. into_iter ( )
1147
1163
. flatten ( )
1148
- . map ( |ident| TypoSuggestion :: typo_from_res ( ident. name , res) ) ,
1164
+ . map ( |ident| TypoSuggestion :: typo_from_ident ( * ident, res) ) ,
1149
1165
) ;
1150
1166
}
1151
1167
}
@@ -1164,7 +1180,7 @@ impl<'a> Resolver<'a> {
1164
1180
suggestions. extend (
1165
1181
ext. helper_attrs
1166
1182
. iter ( )
1167
- . map ( |name| TypoSuggestion :: typo_from_res ( * name, res) ) ,
1183
+ . map ( |name| TypoSuggestion :: typo_from_name ( * name, res) ) ,
1168
1184
) ;
1169
1185
}
1170
1186
}
@@ -1174,8 +1190,8 @@ impl<'a> Resolver<'a> {
1174
1190
if let MacroRulesScope :: Binding ( macro_rules_binding) = macro_rules_scope. get ( ) {
1175
1191
let res = macro_rules_binding. binding . res ( ) ;
1176
1192
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 ,
1179
1195
res,
1180
1196
) )
1181
1197
}
@@ -1193,7 +1209,7 @@ impl<'a> Resolver<'a> {
1193
1209
suggestions. extend ( this. macro_use_prelude . iter ( ) . filter_map (
1194
1210
|( name, binding) | {
1195
1211
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) )
1197
1213
} ,
1198
1214
) ) ;
1199
1215
}
@@ -1203,22 +1219,22 @@ impl<'a> Resolver<'a> {
1203
1219
suggestions. extend (
1204
1220
BUILTIN_ATTRIBUTES
1205
1221
. iter ( )
1206
- . map ( |attr| TypoSuggestion :: typo_from_res ( attr. name , res) ) ,
1222
+ . map ( |attr| TypoSuggestion :: typo_from_name ( attr. name , res) ) ,
1207
1223
) ;
1208
1224
}
1209
1225
}
1210
1226
Scope :: ExternPrelude => {
1211
1227
suggestions. extend ( this. extern_prelude . iter ( ) . filter_map ( |( ident, _) | {
1212
1228
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) )
1214
1230
} ) ) ;
1215
1231
}
1216
1232
Scope :: ToolPrelude => {
1217
1233
let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ;
1218
1234
suggestions. extend (
1219
1235
this. registered_tools
1220
1236
. iter ( )
1221
- . map ( |ident| TypoSuggestion :: typo_from_res ( ident. name , res) ) ,
1237
+ . map ( |ident| TypoSuggestion :: typo_from_ident ( * ident, res) ) ,
1222
1238
) ;
1223
1239
}
1224
1240
Scope :: StdLibPrelude => {
@@ -1235,7 +1251,8 @@ impl<'a> Resolver<'a> {
1235
1251
Scope :: BuiltinTypes => {
1236
1252
suggestions. extend ( PrimTy :: ALL . iter ( ) . filter_map ( |prim_ty| {
1237
1253
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) )
1239
1256
} ) )
1240
1257
}
1241
1258
}
0 commit comments