Sort enum suggestions
This commit is contained in:
parent
b946ecd020
commit
73f6f5e096
2 changed files with 10 additions and 8 deletions
|
@ -2273,15 +2273,17 @@ impl<'a> Resolver<'a> {
|
||||||
show_candidates(&mut err, &candidates, def.is_some());
|
show_candidates(&mut err, &candidates, def.is_some());
|
||||||
} else if is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) {
|
} else if is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) {
|
||||||
let enum_candidates = this.lookup_import_candidates(name, ns, is_enum_variant);
|
let enum_candidates = this.lookup_import_candidates(name, ns, is_enum_variant);
|
||||||
for suggestion in enum_candidates {
|
let mut enum_candidates = enum_candidates.iter()
|
||||||
let (variant_path, enum_path) = import_candidate_to_paths(&suggestion);
|
.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 `{}`?",
|
let msg = format!("there is an enum variant `{}`, did you mean to use `{}`?",
|
||||||
variant_path,
|
variant_path,
|
||||||
enum_path);
|
enum_path);
|
||||||
if suggestion.path.span == DUMMY_SP {
|
if sp == DUMMY_SP {
|
||||||
err.help(&msg);
|
err.help(&msg);
|
||||||
} else {
|
} 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.
|
/// 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 = &suggestion.path;
|
||||||
let variant_path_string = path_names_to_string(variant_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);
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ error[E0573]: expected type, found variant `Ok`
|
||||||
24 | fn foo() -> Ok {
|
24 | fn foo() -> Ok {
|
||||||
| ^^ not a type
|
| ^^ not a type
|
||||||
|
|
|
|
||||||
= help: there is an enum variant `std::result::Result::Ok`, did you mean to use `std::result::Result`?
|
|
||||||
= help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`?
|
= help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`?
|
||||||
|
= help: there is an enum variant `std::prelude::v1::Result::Ok`, did you mean to use `std::prelude::v1::Result`?
|
||||||
|
|
||||||
error[E0412]: cannot find type `Variant3` in this scope
|
error[E0412]: cannot find type `Variant3` in this scope
|
||||||
--> $DIR/issue-35675.rs:28:13
|
--> $DIR/issue-35675.rs:28:13
|
||||||
|
@ -67,8 +67,8 @@ error[E0573]: expected type, found variant `Some`
|
||||||
31 | fn qux() -> Some {
|
31 | fn qux() -> Some {
|
||||||
| ^^^^ not a type
|
| ^^^^ not a type
|
||||||
|
|
|
|
||||||
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`?
|
|
||||||
= help: there is an enum variant `std::prelude::v1::Option::Some`, did you mean to use `std::prelude::v1::Option`?
|
= help: there is an enum variant `std::prelude::v1::Option::Some`, did you mean to use `std::prelude::v1::Option`?
|
||||||
|
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`?
|
||||||
|
|
||||||
error: aborting due to 7 previous errors
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue