summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/issue-89606.rs
blob: 1bb6aa40f06fafe335845786c6fcf3d81048de25 (plain)
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
36
37
38
39
40
// Regression test for #89606. Used to ICE.
//
// check-pass
// revisions: twenty_eighteen twenty_twentyone
// [twenty_eighteen]compile-flags: --edition 2018
// [twenty_twentyone]compile-flags: --edition 2021

struct S<'a>(Option<&'a mut i32>);

fn by_ref(s: &mut S<'_>) {
    (|| {
        let S(_o) = s;
        s.0 = None;
    })();
}

fn by_value(s: S<'_>) {
    (|| {
        let S(ref _o) = s;
        let _g = s.0;
    })();
}

struct V<'a>((Option<&'a mut i32>,));

fn nested(v: &mut V<'_>) {
    (|| {
        let V((_o,)) = v;
        v.0 = (None, );
    })();
}

fn main() {
    let mut s = S(None);
    by_ref(&mut s);
    by_value(s);

    let mut v = V((None, ));
    nested(&mut v);
}