@@ -30,7 +30,6 @@ extern crate syntax;
30
30
#[ no_link]
31
31
extern crate rustc_bitflags;
32
32
extern crate rustc_front;
33
-
34
33
extern crate rustc;
35
34
36
35
use self :: PatternBindingMode :: * ;
@@ -66,7 +65,7 @@ use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32};
66
65
use syntax:: attr:: AttrMetaMethods ;
67
66
use syntax:: parse:: token:: { self , special_names, special_idents} ;
68
67
use syntax:: codemap:: { self , Span , Pos } ;
69
- use syntax:: util:: lev_distance:: { lev_distance , max_suggestion_distance } ;
68
+ use syntax:: util:: lev_distance:: find_best_match_for_name ;
70
69
71
70
use rustc_front:: intravisit:: { self , FnKind , Visitor } ;
72
71
use rustc_front:: hir;
@@ -91,7 +90,6 @@ use std::cell::{Cell, RefCell};
91
90
use std:: fmt;
92
91
use std:: mem:: replace;
93
92
use std:: rc:: { Rc , Weak } ;
94
- use std:: usize;
95
93
96
94
use resolve_imports:: { Target , ImportDirective , ImportResolutionPerNamespace } ;
97
95
use resolve_imports:: Shadowable ;
@@ -118,7 +116,7 @@ macro_rules! execute_callback {
118
116
119
117
enum SuggestionType {
120
118
Macro ( String ) ,
121
- Function ( String ) ,
119
+ Function ( token :: InternedString ) ,
122
120
NotFound ,
123
121
}
124
122
@@ -3422,39 +3420,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3422
3420
NoSuggestion
3423
3421
}
3424
3422
3425
- fn find_best_match_for_name ( & mut self , name : & str ) -> SuggestionType {
3426
- let mut maybes: Vec < token:: InternedString > = Vec :: new ( ) ;
3427
- let mut values: Vec < usize > = Vec :: new ( ) ;
3428
-
3423
+ fn find_best_match ( & mut self , name : & str ) -> SuggestionType {
3429
3424
if let Some ( macro_name) = self . session . available_macros
3430
- . borrow ( ) . iter ( ) . find ( |n| n. as_str ( ) == name) {
3425
+ . borrow ( ) . iter ( ) . find ( |n| n. as_str ( ) == name) {
3431
3426
return SuggestionType :: Macro ( format ! ( "{}!" , macro_name) ) ;
3432
3427
}
3433
3428
3434
- for rib in self . value_ribs . iter ( ) . rev ( ) {
3435
- for ( & k, _) in & rib. bindings {
3436
- maybes. push ( k. as_str ( ) ) ;
3437
- values. push ( usize:: MAX ) ;
3438
- }
3439
- }
3440
-
3441
- let mut smallest = 0 ;
3442
- for ( i, other) in maybes. iter ( ) . enumerate ( ) {
3443
- values[ i] = lev_distance ( name, & other) ;
3429
+ let names = self . value_ribs
3430
+ . iter ( )
3431
+ . rev ( )
3432
+ . flat_map ( |rib| rib. bindings . keys ( ) ) ;
3444
3433
3445
- if values[ i] <= values[ smallest] {
3446
- smallest = i;
3434
+ if let Some ( found) = find_best_match_for_name ( names, name, None ) {
3435
+ if name != & * found {
3436
+ return SuggestionType :: Function ( found) ;
3447
3437
}
3448
- }
3449
-
3450
- let max_distance = max_suggestion_distance ( name) ;
3451
- if !values. is_empty ( ) && values[ smallest] <= max_distance && name != & maybes[ smallest] [ ..] {
3452
-
3453
- SuggestionType :: Function ( maybes[ smallest] . to_string ( ) )
3454
-
3455
- } else {
3456
- SuggestionType :: NotFound
3457
- }
3438
+ } SuggestionType :: NotFound
3458
3439
}
3459
3440
3460
3441
fn resolve_expr ( & mut self , expr : & Expr ) {
@@ -3568,7 +3549,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3568
3549
NoSuggestion => {
3569
3550
// limit search to 5 to reduce the number
3570
3551
// of stupid suggestions
3571
- match self . find_best_match_for_name ( & path_name) {
3552
+ match self . find_best_match ( & path_name) {
3572
3553
SuggestionType :: Macro ( s) => {
3573
3554
format ! ( "the macro `{}`" , s)
3574
3555
}
0 commit comments