From 34b75664ee01f4c19ee67480c5711b7300db5f41 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Sat, 13 Nov 2021 15:06:22 +0900 Subject: [PATCH] Type can be unsized and uninhabited --- compiler/rustc_middle/src/ty/layout.rs | 2 +- src/test/ui/issues/issue-88150.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issues/issue-88150.rs diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index b87e23af72b..a8dec82c883 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -512,7 +512,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { } } - if sized && fields.iter().any(|f| f.abi.is_uninhabited()) { + if fields.iter().any(|f| f.abi.is_uninhabited()) { abi = Abi::Uninhabited; } diff --git a/src/test/ui/issues/issue-88150.rs b/src/test/ui/issues/issue-88150.rs new file mode 100644 index 00000000000..555a38637a4 --- /dev/null +++ b/src/test/ui/issues/issue-88150.rs @@ -0,0 +1,21 @@ +// run-pass +// compile-flags:-C debuginfo=2 +// edition:2018 + +use core::marker::PhantomData; + +pub struct Foo( + PhantomData<(A, T)>, +); + +enum Never {} + +impl Foo { + fn new_foo() -> Foo { + Foo(PhantomData) + } +} + +fn main() { + let _ = Foo::<[()], Never>::new_foo(); +}