From eddae8b02e3c63924220e5e79b6d94fcc501a1bb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 14 Dec 2023 07:57:36 +0100 Subject: [PATCH] add test for uninhabited saved locals in a coroutine --- tests/pass/coroutine.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/pass/coroutine.rs b/tests/pass/coroutine.rs index 49bfa92a05..7e1f64df04 100644 --- a/tests/pass/coroutine.rs +++ b/tests/pass/coroutine.rs @@ -220,7 +220,38 @@ fn smoke_resume_arg() { }); } +fn uninit_fields() { + // Test that uninhabited saved local doesn't make the entire variant uninhabited. + // (https://github.com/rust-lang/rust/issues/115145, https://github.com/rust-lang/rust/pull/118871) + fn conjure() -> T { + loop {} + } + + fn run(x: bool, y: bool) { + let mut c = || { + if x { + let _a: T; + if y { + _a = conjure::(); + } + yield (); + } else { + let _a: T; + if y { + _a = conjure::(); + } + yield (); + } + }; + assert!(matches!(Pin::new(&mut c).resume(()), CoroutineState::Yielded(()))); + assert!(matches!(Pin::new(&mut c).resume(()), CoroutineState::Complete(()))); + } + + run::(false, false); +} + fn main() { basic(); smoke_resume_arg(); + uninit_fields(); }