summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_no_migrations.rs
blob: 3f184a67fbac93b728fac5ccce07a6a4500cf71f (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
41
42
43
44
45
// run-pass

#![deny(rust_2021_incompatible_closure_captures)]
#![feature(rustc_attrs)]
#![allow(unused)]
#[rustc_insignificant_dtor]

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

impl Drop for InsignificantDropPoint {
    fn drop(&mut self) {}
}

struct GenericStruct<T>(T, T);

// No drop reordering is required as the elements of `t` implement insignificant drop
fn insignificant_drop_does_not_need_migration() {
    let t = (InsignificantDropPoint { x: 4, y: 9 }, InsignificantDropPoint { x: 4, y: 9 });

    let c = || {
        let _t = t.0;
    };

    c();
}

// Generic struct whose elements don't have significant drops don't need drop reordering
fn generic_struct_with_insignificant_drop_does_not_need_migration() {
    let t =
        GenericStruct(InsignificantDropPoint { x: 4, y: 9 }, InsignificantDropPoint { x: 4, y: 9 });

    let c = || {
        let _t = t.0;
    };

    c();
}

fn main() {
    insignificant_drop_does_not_need_migration();
    generic_struct_with_insignificant_drop_does_not_need_migration();
}