diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs index 4d9e296d5441b..d1711177bfe7d 100644 --- a/compiler/rustc_const_eval/src/interpret/projection.rs +++ b/compiler/rustc_const_eval/src/interpret/projection.rs @@ -202,11 +202,6 @@ where // see https://github.com/rust-lang/rust/issues/93688#issuecomment-1032929496.) // So we just "offset" by 0. let layout = base.layout().for_variant(self, variant); - if layout.abi.is_uninhabited() { - // `read_discriminant` should have excluded uninhabited variants... but ConstProp calls - // us on dead code. - throw_inval!(ConstPropNonsense) - } // This cannot be `transmute` as variants *can* have a smaller size than the entire enum. base.offset(Size::ZERO, layout, self) } diff --git a/src/tools/miri/tests/pass/issues/issue-115145-project-downcast-uninhabited.rs b/src/tools/miri/tests/pass/issues/issue-115145-project-downcast-uninhabited.rs new file mode 100644 index 0000000000000..1f42d3b0f919c --- /dev/null +++ b/src/tools/miri/tests/pass/issues/issue-115145-project-downcast-uninhabited.rs @@ -0,0 +1,25 @@ +#![feature(noop_waker)] +use std::future::Future; + +enum Runtime {} + +async fn run(_: Runtime) {} + +async fn apply_timeout() { + let c = async {}; + match None:: { + None => { + c.await; + }, + Some(r) => { + run(r).await; + } + } +} + +fn main() { + let waker = std::task::Waker::noop(); + let mut ctx = std::task::Context::from_waker(&waker); + let fut = std::pin::pin!(apply_timeout()); + let _ = fut.poll(&mut ctx); +}