about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuanqun Lu <guanqun.lu@gmail.com>2019-09-21 23:36:12 +0800
committerGuanqun Lu <guanqun.lu@gmail.com>2019-09-21 23:38:35 +0800
commite001c5f9d894a66722db061ecbbd224973dc0fb8 (patch)
tree460e7c212b6cbb7ef0cb042bd1f53332134f577a
parent9ad1e7c46cf690b7ec6953b142430d21ca2d8799 (diff)
downloadrust-e001c5f9d894a66722db061ecbbd224973dc0fb8.tar.gz
rust-e001c5f9d894a66722db061ecbbd224973dc0fb8.zip
unify errors for tuple/struct variants
fix #63983
-rw-r--r--src/librustc_resolve/late/diagnostics.rs6
-rw-r--r--src/test/ui/empty/empty-struct-tuple-pat.stderr7
-rw-r--r--src/test/ui/issues/issue-32004.stderr5
-rw-r--r--src/test/ui/issues/issue-63983.rs15
-rw-r--r--src/test/ui/issues/issue-63983.stderr15
5 files changed, 43 insertions, 5 deletions
diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs
index 0c86d8494fd..1d4fa77adcc 100644
--- a/src/librustc_resolve/late/diagnostics.rs
+++ b/src/librustc_resolve/late/diagnostics.rs
@@ -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");
diff --git a/src/test/ui/empty/empty-struct-tuple-pat.stderr b/src/test/ui/empty/empty-struct-tuple-pat.stderr
index 777b9d4a4ac..6c15e7bf282 100644
--- a/src/test/ui/empty/empty-struct-tuple-pat.stderr
+++ b/src/test/ui/empty/empty-struct-tuple-pat.stderr
@@ -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
 
diff --git a/src/test/ui/issues/issue-32004.stderr b/src/test/ui/issues/issue-32004.stderr
index f8c418b25a0..b56fa949acb 100644
--- a/src/test/ui/issues/issue-32004.stderr
+++ b/src/test/ui/issues/issue-32004.stderr
@@ -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
diff --git a/src/test/ui/issues/issue-63983.rs b/src/test/ui/issues/issue-63983.rs
new file mode 100644
index 00000000000..c1c79091fc8
--- /dev/null
+++ b/src/test/ui/issues/issue-63983.rs
@@ -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() {}
diff --git a/src/test/ui/issues/issue-63983.stderr b/src/test/ui/issues/issue-63983.stderr
new file mode 100644
index 00000000000..67acd1d57c2
--- /dev/null
+++ b/src/test/ui/issues/issue-63983.stderr
@@ -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`.