summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsafe/issue-45107-unnecessary-unsafe-in-closure.rs
blob: ac1cfd62a05687238f72c36a3ccbcb2697d63bb1 (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
// revisions: mir thir
// [thir]compile-flags: -Zthir-unsafeck

#[deny(unused_unsafe)]
fn main() {
    let mut v = Vec::<i32>::with_capacity(24);

    unsafe {
        let f = |v: &mut Vec<_>| {
            unsafe { //~ ERROR unnecessary `unsafe`
                v.set_len(24);
                |w: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
                    w.set_len(32);
                } };
            }
            |x: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
                x.set_len(40);
            } };
        };

        v.set_len(0);
        f(&mut v);
    }

    |y: &mut Vec<u32>| { unsafe {
        y.set_len(48);
    } };
}