summaryrefslogtreecommitdiffstats
path: root/src/test/ui/closures/2229_closure_analysis/run_pass/edition.rs
blob: 20bbe1d89e45d92152c4aca5fe3a216f3b2ec649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// edition:2021
// run-pass

// Test that edition 2021 enables disjoint capture by default.

struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let mut p = Point { x: 10, y: 10 };

    let c = || {
        println!("{}", p.x);
    };

    // `c` should only capture `p.x`, therefore mutating `p.y` is allowed.
    let py = &mut p.y;

    c();
    *py = 20;
}