diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2017-04-03 07:46:35 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2017-04-03 10:57:45 -0700 |
| commit | 73f6f5e0968ebe032a0730e2e3dfccea5a61c384 (patch) | |
| tree | 787a4eb946ff6b27724ee42f3ac23774b8b55841 /src/librustc_resolve | |
| parent | b946ecd02018d1671c990057d7136176df60da35 (diff) | |
| download | rust-73f6f5e0968ebe032a0730e2e3dfccea5a61c384.tar.gz rust-73f6f5e0968ebe032a0730e2e3dfccea5a61c384.zip | |
Sort enum suggestions
Diffstat (limited to 'src/librustc_resolve')
| -rw-r--r-- | src/librustc_resolve/lib.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a39cd3b0d55..e191fadc01b 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2273,15 +2273,17 @@ impl<'a> Resolver<'a> { show_candidates(&mut err, &candidates, def.is_some()); } else if is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) { let enum_candidates = this.lookup_import_candidates(name, ns, is_enum_variant); - for suggestion in enum_candidates { - let (variant_path, enum_path) = import_candidate_to_paths(&suggestion); + let mut enum_candidates = enum_candidates.iter() + .map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>(); + enum_candidates.sort(); + for (sp, variant_path, enum_path) in enum_candidates { let msg = format!("there is an enum variant `{}`, did you mean to use `{}`?", variant_path, enum_path); - if suggestion.path.span == DUMMY_SP { + if sp == DUMMY_SP { err.help(&msg); } else { - err.span_help(suggestion.path.span, &msg); + err.span_help(sp, &msg); } } } @@ -3437,7 +3439,7 @@ fn path_names_to_string(path: &Path) -> String { } /// Get the path for an enum and the variant from an `ImportSuggestion` for an enum variant. -fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (String, String) { +fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, String) { let variant_path = &suggestion.path; let variant_path_string = path_names_to_string(variant_path); @@ -3448,7 +3450,7 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (String, String) }; let enum_path_string = path_names_to_string(&enum_path); - (variant_path_string, enum_path_string) + (suggestion.path.span, variant_path_string, enum_path_string) } |
