unify errors for tuple/struct variants

fix #63983
This commit is contained in:
Guanqun Lu 2019-09-21 23:36:12 +08:00
parent 9ad1e7c46c
commit e001c5f9d8
5 changed files with 43 additions and 5 deletions

View File

@ -445,6 +445,12 @@ fn smart_resolve_context_dependent_help(
(Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _), _) if ns == ValueNS => {
bad_struct_syntax_suggestion();
}
(Res::Def(DefKind::Ctor(_, CtorKind::Fn), _), _) if ns == ValueNS => {
err.span_label(
span,
format!("did you mean `{} ( /* fields */ )`?", path_str),
);
}
(Res::SelfTy(..), _) if ns == ValueNS => {
err.span_label(span, fallback_label);
err.note("can't use `Self` as a constructor, you must use the implemented struct");

View File

@ -20,15 +20,16 @@ error[E0532]: expected unit struct/variant or constant, found tuple variant `E::
--> $DIR/empty-struct-tuple-pat.rs:29:9
|
LL | E::Empty4 => ()
| ^^^^^^^^^ not a unit struct/variant or constant
| ^^^^^^^^^ did you mean `E::Empty4 ( /* fields */ )`?
error[E0532]: expected unit struct/variant or constant, found tuple variant `XE::XEmpty5`
--> $DIR/empty-struct-tuple-pat.rs:33:9
|
LL | XE::XEmpty5 => (),
| ^^^^-------
| |
| help: a unit variant with a similar name exists: `XEmpty4`
| | |
| | help: a unit variant with a similar name exists: `XEmpty4`
| did you mean `XE::XEmpty5 ( /* fields */ )`?
error: aborting due to 4 previous errors

View File

@ -3,8 +3,9 @@ error[E0532]: expected unit struct/variant or constant, found tuple variant `Foo
|
LL | Foo::Bar => {}
| ^^^^^---
| |
| help: a unit variant with a similar name exists: `Baz`
| | |
| | help: a unit variant with a similar name exists: `Baz`
| did you mean `Foo::Bar ( /* fields */ )`?
error[E0532]: expected tuple struct/variant, found unit struct `S`
--> $DIR/issue-32004.rs:16:9

View File

@ -0,0 +1,15 @@
enum MyEnum {
Tuple(i32),
Struct{ s: i32 },
}
fn foo(en: MyEnum) {
match en {
MyEnum::Tuple => "",
//~^ ERROR expected unit struct/variant or constant, found tuple variant `MyEnum::Tuple`
MyEnum::Struct => "",
//~^ ERROR expected unit struct/variant or constant, found struct variant `MyEnum::Struct`
};
}
fn main() {}

View File

@ -0,0 +1,15 @@
error[E0532]: expected unit struct/variant or constant, found tuple variant `MyEnum::Tuple`
--> $DIR/issue-63983.rs:8:9
|
LL | MyEnum::Tuple => "",
| ^^^^^^^^^^^^^ did you mean `MyEnum::Tuple ( /* fields */ )`?
error[E0532]: expected unit struct/variant or constant, found struct variant `MyEnum::Struct`
--> $DIR/issue-63983.rs:10:9
|
LL | MyEnum::Struct => "",
| ^^^^^^^^^^^^^^ did you mean `MyEnum::Struct { /* fields */ }`?
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0532`.