diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs index 72a47c0028162..bd67dd2e6b25d 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 0000000000000..9cf1c7d6de8a4 --- /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 or the MIT license +// , 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 0000000000000..fc90c8a2b20be --- /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 +