提交 39f848ef 编写于 作者: M Maxim Zholobak

Add module population and case of enum in place of expression

上级 08c81c1a
......@@ -2599,13 +2599,14 @@ fn smart_resolve_path_fragment(&mut self,
}
_ => {}
},
(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 @@ fn collect_enum_variants(&mut self, enum_def: Def) -> Option<Vec<Path>> {
}
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() {}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册