File: ref-upvar-not-send.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (31 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// For `Send` coroutines, suggest a `T: Sync` requirement for `&T` upvars,
// and suggest a `T: Send` requirement for `&mut T` upvars.

#![feature(coroutines, stmt_expr_attributes)]

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();
    assert_send(#[coroutine] move || {
        //~^ ERROR coroutine cannot be sent between threads safely
        //~| NOTE coroutine is not `Send`
        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`
    assert_send(#[coroutine] move || {
        //~^ ERROR coroutine cannot be sent between threads safely
        //~| NOTE coroutine is not `Send`
        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`
}