summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs
blob: a2290d850207d2bcfebfec3edfa3b50072a3c541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// edition:2021

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}
fn foo () -> impl FnMut()->() {
    let mut p = Point {x: 1, y: 2 };
    let mut c = || {
    //~^ ERROR closure may outlive the current function, but it borrows `p`
       p.x+=5;
       println!("{:?}", p);
    };
    c
}
fn main() {
    let c = foo();
    c();
}