@@ -22,12 +22,14 @@ use rustc::traits::{Obligation, SelectionContext};
22
22
use util:: nodemap:: FxHashSet ;
23
23
24
24
use syntax:: ast;
25
+ use syntax:: util:: lev_distance:: find_best_match_for_name;
25
26
use errors:: DiagnosticBuilder ;
26
27
use syntax_pos:: Span ;
27
28
28
29
use rustc:: hir;
29
30
use rustc:: hir:: print;
30
31
use rustc:: infer:: type_variable:: TypeVariableOrigin ;
32
+ use rustc:: ty:: TyAdt ;
31
33
32
34
use std:: cell;
33
35
use std:: cmp:: Ordering ;
@@ -179,9 +181,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
179
181
let actual = self . resolve_type_vars_if_possible ( & rcvr_ty) ;
180
182
let ty_string = self . ty_to_string ( actual) ;
181
183
let is_method = mode == Mode :: MethodCall ;
184
+ let mut suggestion = None ;
182
185
let type_str = if is_method {
183
186
"method"
184
187
} else if actual. is_enum ( ) {
188
+ if let TyAdt ( ref adt_def, _) = actual. sty {
189
+ let names = adt_def. variants . iter ( ) . map ( |s| & s. name ) ;
190
+ suggestion = find_best_match_for_name ( names,
191
+ & item_name. as_str ( ) ,
192
+ None ) ;
193
+ }
185
194
"variant"
186
195
} else {
187
196
match ( item_name. as_str ( ) . chars ( ) . next ( ) , actual. is_fresh_ty ( ) ) {
@@ -256,15 +265,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
256
265
err. emit ( ) ;
257
266
return ;
258
267
} else {
259
- struct_span_err ! (
268
+ let mut err = struct_span_err ! (
260
269
tcx. sess,
261
270
span,
262
271
E0599 ,
263
272
"no {} named `{}` found for type `{}` in the current scope" ,
264
273
type_str,
265
274
item_name,
266
275
ty_string
267
- )
276
+ ) ;
277
+ if let Some ( suggestion) = suggestion {
278
+ err. note ( & format ! ( "did you mean `{}::{}`?" , type_str, suggestion) ) ;
279
+ }
280
+ err
268
281
}
269
282
} else {
270
283
tcx. sess . diagnostic ( ) . struct_dummy ( )
0 commit comments