2023-10-19 21:46:28 +00:00
|
|
|
#![feature(coroutines)]
|
|
|
|
#![feature(coroutine_clone)]
|
|
|
|
#![feature(coroutine_trait)]
|
2023-02-27 13:07:44 +00:00
|
|
|
#![feature(rustc_attrs, stmt_expr_attributes)]
|
2023-01-21 10:03:12 +00:00
|
|
|
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::Coroutine;
|
2023-01-21 10:03:12 +00:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
|
|
fn copy<T: Copy>(x: T) -> T {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut g = || {
|
|
|
|
// This is desuraged as 4 stages:
|
|
|
|
// - allocate a `*mut u8` with `exchange_malloc`;
|
|
|
|
// - create a Box that is ignored for trait computations;
|
|
|
|
// - compute fields (and yields);
|
|
|
|
// - assign to `t`.
|
2023-02-27 13:07:44 +00:00
|
|
|
let t = #[rustc_box]
|
|
|
|
Box::new((5, yield));
|
2023-01-21 10:03:12 +00:00
|
|
|
drop(t);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Allocate the temporary box.
|
|
|
|
Pin::new(&mut g).resume(());
|
|
|
|
|
2023-10-19 21:46:28 +00:00
|
|
|
// The temporary box is in coroutine locals.
|
2023-01-21 10:03:12 +00:00
|
|
|
// As it is not taken into account for trait computation,
|
2023-10-19 21:46:28 +00:00
|
|
|
// the coroutine is `Copy`.
|
2023-01-21 10:03:12 +00:00
|
|
|
let mut h = copy(g);
|
2023-05-07 18:38:52 +00:00
|
|
|
//~^ ERROR the trait bound `Box<(i32, ())>: Copy` is not satisfied in
|
2023-01-21 10:03:12 +00:00
|
|
|
|
|
|
|
// We now have 2 boxes with the same backing allocation:
|
|
|
|
// one inside `g` and one inside `h`.
|
|
|
|
// Proceed and drop `t` in `g`.
|
|
|
|
Pin::new(&mut g).resume(());
|
2023-05-07 18:38:52 +00:00
|
|
|
//~^ ERROR borrow of moved value: `g`
|
2023-01-21 10:03:12 +00:00
|
|
|
|
|
|
|
// Proceed and drop `t` in `h` -> double free!
|
|
|
|
Pin::new(&mut h).resume(());
|
|
|
|
}
|