]> git.lizzy.rs Git - rust.git/blob - src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.rs
Auto merge of #86888 - FabianWolff:issue-86600, r=davidtwco
[rust.git] / src / test / ui / closures / 2229_closure_analysis / migrations / migrations_rustfix.rs
1 // run-rustfix
2 #![deny(rust_2021_incompatible_closure_captures)]
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 = || {
20         //~^ ERROR: drop order
21         //~| NOTE: for more information, see
22         //~| HELP: add a dummy let to cause `t` to be fully captured
23         let _t = t.0;
24     };
25
26     c();
27 }
28
29 fn closure_doesnt_contain_block() {
30     let t = (Foo(0), Foo(0));
31     let c = || t.0;
32     //~^ ERROR: drop order
33     //~| NOTE: for more information, see
34     //~| HELP: add a dummy let to cause `t` to be fully captured
35
36     c();
37 }
38
39 fn main() {
40     closure_contains_block();
41     closure_doesnt_contain_block();
42 }