Skip to content

Commit 1983205

Browse files
estebankpietroalbini
authored andcommitted
Don't panic when accessing enum variant ctor using Self in match
1 parent b8527ab commit 1983205

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
783783
report_unexpected_variant_def(tcx, &def, pat.span, qpath);
784784
return tcx.types.err;
785785
}
786-
Def::VariantCtor(_, CtorKind::Fictive) => {
786+
Def::VariantCtor(_, CtorKind::Fictive) |
787+
Def::VariantCtor(_, CtorKind::Fn) => {
787788
report_unexpected_variant_def(tcx, &def, pat.span, qpath);
788789
return tcx.types.err;
789790
}

src/test/ui/issues/issue-58006.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(type_alias_enum_variants)]
2+
pub enum Enum {
3+
A(usize),
4+
}
5+
6+
impl Enum {
7+
fn foo(&self) -> () {
8+
match self {
9+
Self::A => (),
10+
//~^ ERROR expected unit struct/variant or constant, found tuple variant
11+
}
12+
}
13+
}
14+
15+
fn main() {}

src/test/ui/issues/issue-58006.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0533]: expected unit struct/variant or constant, found tuple variant `<Self>::A`
2+
--> $DIR/issue-58006.rs:9:13
3+
|
4+
LL | Self::A => (),
5+
| ^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0533`.

0 commit comments

Comments
 (0)