Skip to content

Commit

Permalink
unify errors for tuple/struct variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Guanqun Lu committed Sep 21, 2019
1 parent 9ad1e7c commit e001c5f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ impl<'a> LateResolutionVisitor<'a, '_> {
(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");
Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/empty/empty-struct-tuple-pat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/issues/issue-32004.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issues/issue-63983.rs
Original file line number Diff line number Diff line change
@@ -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() {}
15 changes: 15 additions & 0 deletions src/test/ui/issues/issue-63983.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit e001c5f

Please sign in to comment.