File: preserve_field_drop_order2.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie, trixie-backports, trixie-proposed-updates
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (58 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download | duplicates (8)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
//@ run-pass
//@ check-run-results
//@ revisions: twenty_eighteen twenty_twentyone
//@ [twenty_eighteen]compile-flags: --edition 2018
//@ [twenty_twentyone]compile-flags: --edition 2021

#[derive(Debug)]
struct Dropable(&'static str);

impl Drop for Dropable {
    fn drop(&mut self) {
        println!("Dropping {}", self.0)
    }
}

#[derive(Debug)]
struct A {
    x: Dropable,
    y: Dropable,
}

#[derive(Debug)]
struct B {
    c: A,
    d: A,
}

#[derive(Debug)]
struct R<'a> {
    c: &'a A,
    d: &'a A,
}

fn main() {
    let a = A { x: Dropable("x"), y: Dropable("y") };

    let c = move || println!("{:?} {:?}", a.y, a.x);

    c();

    let b = B {
        c: A { x: Dropable("b.c.x"), y: Dropable("b.c.y") },
        d: A { x: Dropable("b.d.x"), y: Dropable("b.d.y") },
    };

    let d = move || println!("{:?} {:?} {:?} {:?}", b.d.y, b.d.x, b.c.y, b.c.x);

    d();

        let r = R {
        c: &A { x: Dropable("r.c.x"), y: Dropable("r.c.y") },
        d: &A { x: Dropable("r.d.x"), y: Dropable("r.d.y") },
    };

    let e = move || println!("{:?} {:?} {:?} {:?}", r.d.y, r.d.x, r.c.y, r.c.x);

    e();
}