@@ -24,7 +24,7 @@ use rustc_span::hygiene::MacroKind;
24
24
use rustc_span:: lev_distance:: find_best_match_for_name;
25
25
use rustc_span:: source_map:: SourceMap ;
26
26
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
27
- use rustc_span:: { BytePos , Span } ;
27
+ use rustc_span:: { BytePos , Span , SyntaxContext } ;
28
28
29
29
use crate :: imports:: { Import , ImportKind , ImportResolver } ;
30
30
use crate :: late:: { PatternSource , Rib } ;
@@ -47,13 +47,15 @@ pub(crate) type Suggestion = (Vec<(Span, String)>, String, Applicability);
47
47
/// similarly named label and whether or not it is reachable.
48
48
pub ( crate ) type LabelSuggestion = ( Ident , bool ) ;
49
49
50
+ #[ derive( Debug ) ]
50
51
pub ( crate ) enum SuggestionTarget {
51
52
/// The target has a similar name as the name used by the programmer (probably a typo)
52
53
SimilarlyNamed ,
53
54
/// The target is the only valid item that can be used in the corresponding context
54
55
SingleItem ,
55
56
}
56
57
58
+ #[ derive( Debug ) ]
57
59
pub ( crate ) struct TypoSuggestion {
58
60
pub candidate : Symbol ,
59
61
pub res : Res ,
@@ -482,11 +484,12 @@ impl<'a> Resolver<'a> {
482
484
module : Module < ' a > ,
483
485
names : & mut Vec < TypoSuggestion > ,
484
486
filter_fn : & impl Fn ( Res ) -> bool ,
487
+ ctxt : Option < SyntaxContext > ,
485
488
) {
486
489
for ( key, resolution) in self . resolutions ( module) . borrow ( ) . iter ( ) {
487
490
if let Some ( binding) = resolution. borrow ( ) . binding {
488
491
let res = binding. res ( ) ;
489
- if filter_fn ( res) {
492
+ if filter_fn ( res) && ctxt . map_or ( true , |ctxt| ctxt == key . ident . span . ctxt ( ) ) {
490
493
names. push ( TypoSuggestion :: typo_from_res ( key. ident . name , res) ) ;
491
494
}
492
495
}
@@ -1181,10 +1184,10 @@ impl<'a> Resolver<'a> {
1181
1184
Scope :: CrateRoot => {
1182
1185
let root_ident = Ident :: new ( kw:: PathRoot , ident. span ) ;
1183
1186
let root_module = this. resolve_crate_root ( root_ident) ;
1184
- this. add_module_candidates ( root_module, & mut suggestions, filter_fn) ;
1187
+ this. add_module_candidates ( root_module, & mut suggestions, filter_fn, None ) ;
1185
1188
}
1186
1189
Scope :: Module ( module, _) => {
1187
- this. add_module_candidates ( module, & mut suggestions, filter_fn) ;
1190
+ this. add_module_candidates ( module, & mut suggestions, filter_fn, None ) ;
1188
1191
}
1189
1192
Scope :: MacroUsePrelude => {
1190
1193
suggestions. extend ( this. macro_use_prelude . iter ( ) . filter_map (
@@ -1221,7 +1224,7 @@ impl<'a> Resolver<'a> {
1221
1224
Scope :: StdLibPrelude => {
1222
1225
if let Some ( prelude) = this. prelude {
1223
1226
let mut tmp_suggestions = Vec :: new ( ) ;
1224
- this. add_module_candidates ( prelude, & mut tmp_suggestions, filter_fn) ;
1227
+ this. add_module_candidates ( prelude, & mut tmp_suggestions, filter_fn, None ) ;
1225
1228
suggestions. extend (
1226
1229
tmp_suggestions
1227
1230
. into_iter ( )
0 commit comments