]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/auto-trait-leak2.rs
Rollup merge of #103159 - cuviper:check_pow-final-try_opt, r=Mark-Simulacrum
[rust.git] / src / test / ui / impl-trait / auto-trait-leak2.rs
1 use std::cell::Cell;
2 use std::rc::Rc;
3
4 // Fast path, main can see the concrete type returned.
5 fn before() -> impl Fn(i32) {
6 //~^ NOTE within this `impl Fn
7 //~| NOTE within the type `impl Fn
8 //~| NOTE expansion of desugaring
9     let p = Rc::new(Cell::new(0));
10     move |x| p.set(x) //~ NOTE used within this closure
11 }
12
13 fn send<T: Send>(_: T) {}
14 //~^ NOTE required by a bound
15 //~| NOTE required by a bound
16 //~| NOTE required by this bound
17 //~| NOTE required by this bound
18
19 fn main() {
20     send(before());
21     //~^ ERROR `Rc<Cell<i32>>` cannot be sent between threads safely
22     //~| NOTE `Rc<Cell<i32>>` cannot be sent between threads safely
23     //~| NOTE required by a bound
24
25     send(after());
26     //~^ ERROR `Rc<Cell<i32>>` cannot be sent between threads safely
27     //~| NOTE `Rc<Cell<i32>>` cannot be sent between threads safely
28     //~| NOTE required by a bound
29 }
30
31 // Deferred path, main has to wait until typeck finishes,
32 // to check if the return type of after is Send.
33 fn after() -> impl Fn(i32) {
34 //~^ NOTE within this `impl Fn(i32)`
35 //~| NOTE in this expansion
36 //~| NOTE appears within the type
37     let p = Rc::new(Cell::new(0));
38     move |x| p.set(x) //~ NOTE used within this closure
39 }