Fix ICE: don't use `struct_variant` on enums

Fix #40221 and add unittest.
This commit is contained in:
Esteban Küber 2017-03-05 21:18:22 -03:00
parent 65e2a1454f
commit ad06fc718b
3 changed files with 39 additions and 1 deletions

View File

@ -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
}

View File

@ -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() {}

View File

@ -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