Skip to content

Commit a972c10

Browse files
authored
Rollup merge of rust-lang#58007 - estebank:issue-58006, r=petrochenkov
Don't panic when accessing enum variant ctor using `Self` in match Fix rust-lang#58006. r? @petrochenkov
2 parents 6b58344 + 74675fe commit a972c10

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/librustc_typeck/check/_match.rs

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

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

+15
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

+9
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)