File: issue-90465.fixed

package info (click to toggle)
rustc 1.70.0%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 722,120 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,001; asm: 2,856
file content (35 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// run-rustfix

#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE lint level is defined here

fn main() {
    struct Foo(u32);
    impl Drop for Foo {
        fn drop(&mut self) {
            println!("dropped {}", self.0);
        }
    }

    let f0 = Foo(0);
    let f1 = Foo(1);

    let c0 = move || {
        let _ = &f0;
        //~^ ERROR changes to closure capture in Rust 2021 will affect drop order
        //~| NOTE for more information
        let _ = f0;
        //~^ NOTE in Rust 2018, this causes the closure to capture `f0`, but in Rust 2021, it has no effect
    };

    let c1 = move || {
        let _ = &f1;
    };

    println!("dropping 0");
    drop(c0);
    println!("dropping 1");
    drop(c1);
    println!("dropped all");
}
//~^ NOTE in Rust 2018, `f0` is dropped here along with the closure, but in Rust 2021 `f0` is not part of the closure