File: box_expr.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • 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 (37 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (2)
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
//@ test-mir-pass: ElaborateDrops
//@ needs-unwind

#![feature(rustc_attrs, stmt_expr_attributes)]

// EMIT_MIR box_expr.main.ElaborateDrops.diff
fn main() {
    // CHECK-LABEL: fn main(
    // CHECK:   [[box:_.*]] = ShallowInitBox(
    // CHECK:   [[ptr:_.*]] = copy ((([[box]].0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>).0: *const S);
    // CHECK:   (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]];
    // CHECK: [[ret]]: {
    // CHECK:   [[box2:_.*]] = move [[box]];
    // CHECK:   [[box3:_.*]] = move [[box2]];
    // CHECK:   std::mem::drop::<Box<S>>(move [[box3]])
    // CHECK: [[unwind]] (cleanup): {
    // CHECK:   [[boxref:_.*]] = &mut [[box]];
    // CHECK:   <Box<S> as Drop>::drop(move [[boxref]])

    let x = #[rustc_box]
    Box::new(S::new());
    drop(x);
}

struct S;

impl S {
    fn new() -> Self {
        S
    }
}

impl Drop for S {
    fn drop(&mut self) {
        println!("splat!");
    }
}