Skip to content

Commit

Permalink
Auto merge of #40285 - estebank:issue-40221, r=frewsxcv
Browse files Browse the repository at this point in the history
Fix ICE: don't use `struct_variant` on enums

Fix #40221 and add unittest.
  • Loading branch information
bors committed Mar 6, 2017
2 parents 65e2a14 + ad06fc7 commit bd62cbf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/librustc_const_eval/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ impl<'tcx> fmt::Display for Pattern<'tcx> {
Some(&adt_def.variants[variant_index])
}
_ => if let ty::TyAdt(adt, _) = self.ty.sty {
Some(adt.struct_variant())
if adt.is_univariant() {
Some(&adt.variants[0])
} else {
None
}
} else {
None
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/missing-items/issue-40221.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum P {
C(PC),
}

enum PC {
Q,
QA,
}

fn test(proto: P) {
match proto {
P::C(PC::Q) => (),
}
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/missing-items/issue-40221.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error[E0004]: non-exhaustive patterns: `C(QA)` not covered
--> $DIR/issue-40221.rs:21:11
|
21 | match proto {
| ^^^^^ pattern `C(QA)` not covered

error: aborting due to previous error

0 comments on commit bd62cbf

Please sign in to comment.