diff options
| author | bors <bors@rust-lang.org> | 2017-03-06 03:24:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-03-06 03:24:09 +0000 |
| commit | bd62cbfdb193299556a256c73244c3f926a6415d (patch) | |
| tree | 68212cdff27863560df62ba5835ffa0c4dd93cea | |
| parent | 65e2a1454f86f759bca475b0956b8e60bf86cabd (diff) | |
| parent | ad06fc718b7236f988dcc7481d5b9e0447a9760e (diff) | |
| download | rust-bd62cbfdb193299556a256c73244c3f926a6415d.tar.gz rust-bd62cbfdb193299556a256c73244c3f926a6415d.zip | |
Auto merge of #40285 - estebank:issue-40221, r=frewsxcv
Fix ICE: don't use `struct_variant` on enums Fix #40221 and add unittest.
| -rw-r--r-- | src/librustc_const_eval/pattern.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/missing-items/issue-40221.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/missing-items/issue-40221.stderr | 8 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs index 72a47c00281..bd67dd2e6b2 100644 --- a/src/librustc_const_eval/pattern.rs +++ b/src/librustc_const_eval/pattern.rs @@ -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 } diff --git a/src/test/ui/missing-items/issue-40221.rs b/src/test/ui/missing-items/issue-40221.rs new file mode 100644 index 00000000000..9cf1c7d6de8 --- /dev/null +++ b/src/test/ui/missing-items/issue-40221.rs @@ -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() {} diff --git a/src/test/ui/missing-items/issue-40221.stderr b/src/test/ui/missing-items/issue-40221.stderr new file mode 100644 index 00000000000..fc90c8a2b20 --- /dev/null +++ b/src/test/ui/missing-items/issue-40221.stderr @@ -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 + |
