]>
Commit | Line | Data |
---|---|---|
cdc7bbd5 | 1 | // run-rustfix |
136023e0 | 2 | #![deny(rust_2021_incompatible_closure_captures)] |
cdc7bbd5 XL |
3 | //~^ NOTE: the lint level is defined here |
4 | ||
5 | // Test the two possible cases for automated migartion using rustfix | |
6 | // - Closure contains a block i.e. `|| { .. };` | |
7 | // - Closure contains just an expr `|| ..;` | |
8 | ||
9 | #[derive(Debug)] | |
10 | struct Foo(i32); | |
11 | impl Drop for Foo { | |
12 | fn drop(&mut self) { | |
13 | println!("{:?} dropped", self.0); | |
14 | } | |
15 | } | |
16 | ||
17 | fn closure_contains_block() { | |
18 | let t = (Foo(0), Foo(0)); | |
19 | let c = || { | |
136023e0 XL |
20 | //~^ ERROR: drop order |
21 | //~| NOTE: for more information, see | |
cdc7bbd5 XL |
22 | //~| HELP: add a dummy let to cause `t` to be fully captured |
23 | let _t = t.0; | |
136023e0 | 24 | //~^ NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0` |
cdc7bbd5 XL |
25 | }; |
26 | ||
27 | c(); | |
28 | } | |
136023e0 | 29 | //~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.0` would be dropped here alongside the closure |
cdc7bbd5 XL |
30 | |
31 | fn closure_doesnt_contain_block() { | |
32 | let t = (Foo(0), Foo(0)); | |
33 | let c = || t.0; | |
136023e0 XL |
34 | //~^ ERROR: drop order |
35 | //~| NOTE: in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0` | |
36 | //~| NOTE: for more information, see | |
cdc7bbd5 XL |
37 | //~| HELP: add a dummy let to cause `t` to be fully captured |
38 | ||
39 | c(); | |
40 | } | |
136023e0 | 41 | //~^ NOTE: in Rust 2018, `t` would be dropped here, but in Rust 2021, only `t.0` would be dropped here alongside the closure |
cdc7bbd5 XL |
42 | |
43 | fn main() { | |
44 | closure_contains_block(); | |
45 | closure_doesnt_contain_block(); | |
46 | } |