mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Auto merge of #40285 - estebank:issue-40221, r=frewsxcv
Fix ICE: don't use `struct_variant` on enums Fix #40221 and add unittest.
This commit is contained in:
commit
bd62cbfdb1
@ -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
|
||||
}
|
||||
|
26
src/test/ui/missing-items/issue-40221.rs
Normal file
26
src/test/ui/missing-items/issue-40221.rs
Normal 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() {}
|
8
src/test/ui/missing-items/issue-40221.stderr
Normal file
8
src/test/ui/missing-items/issue-40221.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user