]> git.lizzy.rs Git - rust.git/commitdiff
Don't panic when accessing enum variant ctor using `Self` in match
authorEsteban Küber <esteban@kuber.com.ar>
Wed, 30 Jan 2019 19:39:56 +0000 (11:39 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Wed, 30 Jan 2019 19:39:56 +0000 (11:39 -0800)
src/librustc_typeck/check/_match.rs
src/test/ui/issues/issue-58006.rs [new file with mode: 0644]
src/test/ui/issues/issue-58006.stderr [new file with mode: 0644]

index 141b8222b1f33807a4e55b373569656f88564651..4203c71a00a41735ed4d588ec9da78d668a1d342 100644 (file)
@@ -784,7 +784,8 @@ fn check_pat_path(
                 report_unexpected_variant_def(tcx, &def, pat.span, qpath);
                 return tcx.types.err;
             }
-            Def::VariantCtor(_, CtorKind::Fictive) => {
+            Def::VariantCtor(_, CtorKind::Fictive) |
+            Def::VariantCtor(_, CtorKind::Fn) => {
                 report_unexpected_variant_def(tcx, &def, pat.span, qpath);
                 return tcx.types.err;
             }
diff --git a/src/test/ui/issues/issue-58006.rs b/src/test/ui/issues/issue-58006.rs
new file mode 100644 (file)
index 0000000..1fb5fef
--- /dev/null
@@ -0,0 +1,15 @@
+#![feature(type_alias_enum_variants)]
+pub enum Enum {
+    A(usize),
+}
+
+impl Enum {
+    fn foo(&self) -> () {
+        match self {
+            Self::A => (),
+            //~^ ERROR expected unit struct/variant or constant, found tuple variant
+        }
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-58006.stderr b/src/test/ui/issues/issue-58006.stderr
new file mode 100644 (file)
index 0000000..c65e3e2
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0533]: expected unit struct/variant or constant, found tuple variant `<Self>::A`
+  --> $DIR/issue-58006.rs:9:13
+   |
+LL |             Self::A => (),
+   |             ^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0533`.