]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/issue-90465.fixed
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / tests / ui / closures / 2229_closure_analysis / issue-90465.fixed
1 // run-rustfix
2
3 #![deny(rust_2021_incompatible_closure_captures)]
4 //~^ NOTE lint level is defined here
5
6 fn main() {
7     struct Foo(u32);
8     impl Drop for Foo {
9         fn drop(&mut self) {
10             println!("dropped {}", self.0);
11         }
12     }
13
14     let f0 = Foo(0);
15     let f1 = Foo(1);
16
17     let c0 = move || {
18         let _ = &f0;
19         //~^ ERROR changes to closure capture in Rust 2021 will affect drop order
20         //~| NOTE for more information
21         let _ = f0;
22         //~^ NOTE in Rust 2018, this causes the closure to capture `f0`, but in Rust 2021, it has no effect
23     };
24
25     let c1 = move || {
26         let _ = &f1;
27     };
28
29     println!("dropping 0");
30     drop(c0);
31     println!("dropping 1");
32     drop(c1);
33     println!("dropped all");
34 }
35 //~^ NOTE in Rust 2018, `f0` is dropped here along with the closure, but in Rust 2021 `f0` is not part of the closure