Skip to content

Commit

Permalink
Auto merge of rust-lang#3225 - RalfJung:coroutine, r=RalfJung
Browse files Browse the repository at this point in the history
add test for uninhabited saved locals in a coroutine

adds the test from rust-lang#118871 in Miri as well
  • Loading branch information
bors committed Dec 14, 2023
2 parents 4a4a896 + 823e2e7 commit 5747646
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/tools/miri/tests/pass/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() -> T {
loop {}
}

fn run<T>(x: bool, y: bool) {
let mut c = || {
if x {
let _a: T;
if y {
_a = conjure::<T>();
}
yield ();
} else {
let _a: T;
if y {
_a = conjure::<T>();
}
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();
}

0 comments on commit 5747646

Please sign in to comment.