]> git.lizzy.rs Git - rust.git/blob - src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.rs
Rollup merge of #85939 - m-ou-se:fix-remove-ref-macro-invocation, r=estebank
[rust.git] / src / test / ui / closures / 2229_closure_analysis / migrations / migrations_rustfix.rs
1 // run-rustfix
2 #![deny(disjoint_capture_migration)]
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 affected for closure because of `capture_disjoint_fields`
21         //~| HELP: add a dummy let to cause `t` to be fully captured
22         let _t = t.0;
23     };
24
25     c();
26 }
27
28 fn closure_doesnt_contain_block() {
29     let t = (Foo(0), Foo(0));
30     let c = || t.0;
31     //~^ ERROR: drop order affected for closure because of `capture_disjoint_fields`
32     //~| HELP: add a dummy let to cause `t` to be fully captured
33
34     c();
35 }
36
37 fn main() {
38     closure_contains_block();
39     closure_doesnt_contain_block();
40 }