Skip to content

Commit

Permalink
Rollup merge of rust-lang#58007 - estebank:issue-58006, r=petrochenkov
Browse files Browse the repository at this point in the history
Don't panic when accessing enum variant ctor using `Self` in match

Fix rust-lang#58006.

r? @petrochenkov
  • Loading branch information
Centril authored Jan 30, 2019
2 parents 6b58344 + 74675fe commit a972c10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
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;
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issues/issue-58006.rs
Original file line number Diff line number Diff line change
@@ -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() {}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-58006.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit a972c10

Please sign in to comment.