2023-10-19 21:46:28 +00:00
|
|
|
// For `Send` coroutines, suggest a `T: Sync` requirement for `&T` upvars,
|
2022-12-17 20:15:57 +00:00
|
|
|
// and suggest a `T: Send` requirement for `&mut T` upvars.
|
|
|
|
|
2024-04-11 13:15:34 +00:00
|
|
|
#![feature(coroutines, stmt_expr_attributes)]
|
2022-12-17 20:15:57 +00:00
|
|
|
|
|
|
|
fn assert_send<T: Send>(_: T) {}
|
|
|
|
//~^ NOTE required by a bound in `assert_send`
|
|
|
|
//~| NOTE required by this bound in `assert_send`
|
|
|
|
//~| NOTE required by a bound in `assert_send`
|
|
|
|
//~| NOTE required by this bound in `assert_send`
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x: &*mut () = &std::ptr::null_mut();
|
|
|
|
let y: &mut *mut () = &mut std::ptr::null_mut();
|
2024-04-11 13:15:34 +00:00
|
|
|
assert_send(#[coroutine] move || {
|
2023-10-19 21:46:28 +00:00
|
|
|
//~^ ERROR coroutine cannot be sent between threads safely
|
|
|
|
//~| NOTE coroutine is not `Send`
|
2022-12-17 20:15:57 +00:00
|
|
|
yield;
|
|
|
|
let _x = x;
|
|
|
|
});
|
|
|
|
//~^^ NOTE captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
|
|
|
|
//~| NOTE has type `&*mut ()` which is not `Send`, because `*mut ()` is not `Sync`
|
2024-04-11 13:15:34 +00:00
|
|
|
assert_send(#[coroutine] move || {
|
2023-10-19 21:46:28 +00:00
|
|
|
//~^ ERROR coroutine cannot be sent between threads safely
|
|
|
|
//~| NOTE coroutine is not `Send`
|
2022-12-17 20:15:57 +00:00
|
|
|
yield;
|
|
|
|
let _y = y;
|
|
|
|
});
|
|
|
|
//~^^ NOTE captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send`
|
|
|
|
//~| NOTE has type `&mut *mut ()` which is not `Send`, because `*mut ()` is not `Send`
|
|
|
|
}
|