@@ -33,7 +33,6 @@ extern crate syntax;
33
33
#[ no_link]
34
34
extern crate rustc_bitflags;
35
35
extern crate rustc_front;
36
-
37
36
extern crate rustc;
38
37
39
38
use self :: PatternBindingMode :: * ;
@@ -69,7 +68,7 @@ use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32};
69
68
use syntax:: attr:: AttrMetaMethods ;
70
69
use syntax:: parse:: token:: { self , special_names, special_idents} ;
71
70
use syntax:: codemap:: { self , Span , Pos } ;
72
- use syntax:: util:: lev_distance:: { lev_distance , max_suggestion_distance } ;
71
+ use syntax:: util:: lev_distance:: find_best_match_for_name ;
73
72
74
73
use rustc_front:: intravisit:: { self , FnKind , Visitor } ;
75
74
use rustc_front:: hir;
@@ -94,7 +93,6 @@ use std::cell::{Cell, RefCell};
94
93
use std:: fmt;
95
94
use std:: mem:: replace;
96
95
use std:: rc:: { Rc , Weak } ;
97
- use std:: usize;
98
96
99
97
use resolve_imports:: { Target , ImportDirective , ImportResolutionPerNamespace } ;
100
98
use resolve_imports:: Shadowable ;
@@ -121,7 +119,7 @@ macro_rules! execute_callback {
121
119
122
120
enum SuggestionType {
123
121
Macro ( String ) ,
124
- Function ( String ) ,
122
+ Function ( token :: InternedString ) ,
125
123
NotFound ,
126
124
}
127
125
@@ -3352,39 +3350,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3352
3350
NoSuggestion
3353
3351
}
3354
3352
3355
- fn find_best_match_for_name ( & mut self , name : & str ) -> SuggestionType {
3356
- let mut maybes: Vec < token:: InternedString > = Vec :: new ( ) ;
3357
- let mut values: Vec < usize > = Vec :: new ( ) ;
3358
-
3353
+ fn find_best_match ( & mut self , name : & str ) -> SuggestionType {
3359
3354
if let Some ( macro_name) = self . session . available_macros
3360
- . borrow ( ) . iter ( ) . find ( |n| n. as_str ( ) == name) {
3355
+ . borrow ( ) . iter ( ) . find ( |n| n. as_str ( ) == name) {
3361
3356
return SuggestionType :: Macro ( format ! ( "{}!" , macro_name) ) ;
3362
3357
}
3363
3358
3364
- for rib in self . value_ribs . iter ( ) . rev ( ) {
3365
- for ( & k, _) in & rib. bindings {
3366
- maybes. push ( k. as_str ( ) ) ;
3367
- values. push ( usize:: MAX ) ;
3368
- }
3369
- }
3370
-
3371
- let mut smallest = 0 ;
3372
- for ( i, other) in maybes. iter ( ) . enumerate ( ) {
3373
- values[ i] = lev_distance ( name, & other) ;
3359
+ let names = self . value_ribs
3360
+ . iter ( )
3361
+ . rev ( )
3362
+ . flat_map ( |rib| rib. bindings . keys ( ) ) ;
3374
3363
3375
- if values[ i] <= values[ smallest] {
3376
- smallest = i;
3364
+ if let Some ( found) = find_best_match_for_name ( names, name, None ) {
3365
+ if name != & * found {
3366
+ return SuggestionType :: Function ( found) ;
3377
3367
}
3378
- }
3379
-
3380
- let max_distance = max_suggestion_distance ( name) ;
3381
- if !values. is_empty ( ) && values[ smallest] <= max_distance && name != & maybes[ smallest] [ ..] {
3382
-
3383
- SuggestionType :: Function ( maybes[ smallest] . to_string ( ) )
3384
-
3385
- } else {
3386
- SuggestionType :: NotFound
3387
- }
3368
+ } SuggestionType :: NotFound
3388
3369
}
3389
3370
3390
3371
fn resolve_expr ( & mut self , expr : & Expr ) {
@@ -3495,7 +3476,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3495
3476
NoSuggestion => {
3496
3477
// limit search to 5 to reduce the number
3497
3478
// of stupid suggestions
3498
- match self . find_best_match_for_name ( & path_name) {
3479
+ match self . find_best_match ( & path_name) {
3499
3480
SuggestionType :: Macro ( s) => {
3500
3481
format ! ( "the macro `{}`" , s)
3501
3482
}
0 commit comments