Skip to content

Commit 5747646

Browse files
committed
Auto merge of rust-lang#3225 - RalfJung:coroutine, r=RalfJung
add test for uninhabited saved locals in a coroutine adds the test from rust-lang#118871 in Miri as well
2 parents 4a4a896 + 823e2e7 commit 5747646

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/tools/miri/tests/pass/coroutine.rs

+31
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,38 @@ fn smoke_resume_arg() {
220220
});
221221
}
222222

223+
fn uninit_fields() {
224+
// Test that uninhabited saved local doesn't make the entire variant uninhabited.
225+
// (https://github.com/rust-lang/rust/issues/115145, https://github.com/rust-lang/rust/pull/118871)
226+
fn conjure<T>() -> T {
227+
loop {}
228+
}
229+
230+
fn run<T>(x: bool, y: bool) {
231+
let mut c = || {
232+
if x {
233+
let _a: T;
234+
if y {
235+
_a = conjure::<T>();
236+
}
237+
yield ();
238+
} else {
239+
let _a: T;
240+
if y {
241+
_a = conjure::<T>();
242+
}
243+
yield ();
244+
}
245+
};
246+
assert!(matches!(Pin::new(&mut c).resume(()), CoroutineState::Yielded(())));
247+
assert!(matches!(Pin::new(&mut c).resume(()), CoroutineState::Complete(())));
248+
}
249+
250+
run::<!>(false, false);
251+
}
252+
223253
fn main() {
224254
basic();
225255
smoke_resume_arg();
256+
uninit_fields();
226257
}

0 commit comments

Comments
 (0)