Skip to content

Commit 73f6f5e

Browse files
committed
Sort enum suggestions
1 parent b946ecd commit 73f6f5e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/librustc_resolve/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -2273,15 +2273,17 @@ impl<'a> Resolver<'a> {
22732273
show_candidates(&mut err, &candidates, def.is_some());
22742274
} else if is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) {
22752275
let enum_candidates = this.lookup_import_candidates(name, ns, is_enum_variant);
2276-
for suggestion in enum_candidates {
2277-
let (variant_path, enum_path) = import_candidate_to_paths(&suggestion);
2276+
let mut enum_candidates = enum_candidates.iter()
2277+
.map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>();
2278+
enum_candidates.sort();
2279+
for (sp, variant_path, enum_path) in enum_candidates {
22782280
let msg = format!("there is an enum variant `{}`, did you mean to use `{}`?",
22792281
variant_path,
22802282
enum_path);
2281-
if suggestion.path.span == DUMMY_SP {
2283+
if sp == DUMMY_SP {
22822284
err.help(&msg);
22832285
} else {
2284-
err.span_help(suggestion.path.span, &msg);
2286+
err.span_help(sp, &msg);
22852287
}
22862288
}
22872289
}
@@ -3437,7 +3439,7 @@ fn path_names_to_string(path: &Path) -> String {
34373439
}
34383440

34393441
/// Get the path for an enum and the variant from an `ImportSuggestion` for an enum variant.
3440-
fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (String, String) {
3442+
fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, String) {
34413443
let variant_path = &suggestion.path;
34423444
let variant_path_string = path_names_to_string(variant_path);
34433445

@@ -3448,7 +3450,7 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (String, String)
34483450
};
34493451
let enum_path_string = path_names_to_string(&enum_path);
34503452

3451-
(variant_path_string, enum_path_string)
3453+
(suggestion.path.span, variant_path_string, enum_path_string)
34523454
}
34533455

34543456

src/test/ui/did_you_mean/issue-35675.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ error[E0573]: expected type, found variant `Ok`
4646
24 | fn foo() -> Ok {
4747
| ^^ not a type
4848
|
49-
= help: there is an enum variant `std::result::Result::Ok`, did you mean to use `std::result::Result`?
5049
= help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`?
50+
= help: there is an enum variant `std::prelude::v1::Result::Ok`, did you mean to use `std::prelude::v1::Result`?
5151

5252
error[E0412]: cannot find type `Variant3` in this scope
5353
--> $DIR/issue-35675.rs:28:13
@@ -67,8 +67,8 @@ error[E0573]: expected type, found variant `Some`
6767
31 | fn qux() -> Some {
6868
| ^^^^ not a type
6969
|
70-
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`?
7170
= help: there is an enum variant `std::prelude::v1::Option::Some`, did you mean to use `std::prelude::v1::Option`?
71+
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`?
7272

7373
error: aborting due to 7 previous errors
7474

0 commit comments

Comments
 (0)