Add module population and case of enum in place of expression
This commit is contained in:
parent
08c81c1a79
commit
39f848efb0
3 changed files with 31 additions and 9 deletions
|
|
@ -2599,13 +2599,14 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
_ => {}
|
||||
},
|
||||
(Def::Enum(..), PathSource::TupleStruct) => {
|
||||
(Def::Enum(..), PathSource::TupleStruct)
|
||||
| (Def::Enum(..), PathSource::Expr(..)) => {
|
||||
if let Some(variants) = this.collect_enum_variants(def) {
|
||||
err.note(&format!("did you mean to use one \
|
||||
of the following variants?\n{}",
|
||||
variants.iter()
|
||||
.map(|suggestion| format!("- `{}`",
|
||||
path_names_to_string(suggestion)))
|
||||
.map(|suggestion| path_names_to_string(suggestion))
|
||||
.map(|suggestion| format!("- `{}`", suggestion))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")));
|
||||
|
||||
|
|
@ -3559,6 +3560,8 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
self.find_module(enum_def).map(|(enum_module, enum_import_suggestion)| {
|
||||
self.populate_module_if_necessary(enum_module);
|
||||
|
||||
let mut variants = Vec::new();
|
||||
enum_module.for_each_child_stable(|ident, _, name_binding| {
|
||||
if let Def::Variant(..) = name_binding.def() {
|
||||
|
|
|
|||
|
|
@ -8,12 +8,20 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
enum Example { Ex(String), NotEx }
|
||||
|
||||
fn result_test() {
|
||||
let x = Option(1);
|
||||
|
||||
if let Option(_) = x {
|
||||
println!("It is OK.");
|
||||
}
|
||||
|
||||
let y = Example::Ex(String::from("test"));
|
||||
|
||||
if let Example(_) = y {
|
||||
println!("It is OK.");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
error[E0423]: expected function, found enum `Option`
|
||||
--> $DIR/issue-43871-enum-instead-of-variant.rs:12:13
|
||||
--> $DIR/issue-43871-enum-instead-of-variant.rs:14:13
|
||||
|
|
||||
14 | let x = Option(1);
|
||||
| ^^^^^^
|
||||
|
|
||||
12 | let x = Option(1);
|
||||
| ^^^^^^ not a function
|
||||
= note: did you mean to use one of the following variants?
|
||||
- `std::prelude::v1::Option::None`
|
||||
- `std::prelude::v1::Option::Some`
|
||||
|
||||
error[E0532]: expected tuple struct/variant, found enum `Option`
|
||||
--> $DIR/issue-43871-enum-instead-of-variant.rs:14:12
|
||||
--> $DIR/issue-43871-enum-instead-of-variant.rs:16:12
|
||||
|
|
||||
14 | if let Option(_) = x {
|
||||
16 | if let Option(_) = x {
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: did you mean to use one of the following variants?
|
||||
- `std::prelude::v1::Option::None`
|
||||
- `std::prelude::v1::Option::Some`
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0532]: expected tuple struct/variant, found enum `Example`
|
||||
--> $DIR/issue-43871-enum-instead-of-variant.rs:22:12
|
||||
|
|
||||
22 | if let Example(_) = y {
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: did you mean to use one of the following variants?
|
||||
- `Example::Ex`
|
||||
- `Example::NotEx`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue