]> git.lizzy.rs Git - rust.git/blob - tests/ui/generator/ref-upvar-not-send.rs
Auto merge of #106458 - albertlarsan68:move-tests, r=jyn514
[rust.git] / tests / ui / generator / ref-upvar-not-send.rs
1 // For `Send` generators, suggest a `T: Sync` requirement for `&T` upvars,
2 // and suggest a `T: Send` requirement for `&mut T` upvars.
3
4 #![feature(generators)]
5
6 fn assert_send<T: Send>(_: T) {}
7 //~^ NOTE required by a bound in `assert_send`
8 //~| NOTE required by this bound in `assert_send`
9 //~| NOTE required by a bound in `assert_send`
10 //~| NOTE required by this bound in `assert_send`
11
12 fn main() {
13     let x: &*mut () = &std::ptr::null_mut();
14     let y: &mut *mut () = &mut std::ptr::null_mut();
15     assert_send(move || {
16         //~^ ERROR generator cannot be sent between threads safely
17         //~| NOTE generator is not `Send`
18         yield;
19         let _x = x;
20     });
21     //~^^ NOTE captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
22     //~| NOTE has type `&*mut ()` which is not `Send`, because `*mut ()` is not `Sync`
23     assert_send(move || {
24         //~^ ERROR generator cannot be sent between threads safely
25         //~| NOTE generator is not `Send`
26         yield;
27         let _y = y;
28     });
29     //~^^ NOTE captured value is not `Send` because `&mut` references cannot be sent unless their referent is `Send`
30     //~| NOTE has type `&mut *mut ()` which is not `Send`, because `*mut ()` is not `Send`
31 }