File: clone_as_copy.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 (45 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (3)
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
//@ compile-flags: -Zunsound-mir-opts
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
//@ compile-flags: -Cdebuginfo=full

// Check if we have transformed the nested clone to the copy in the complete pipeline.

#[derive(Clone)]
struct AllCopy {
    a: i32,
    b: u64,
    c: [i8; 3],
}

#[derive(Clone)]
struct NestCopy {
    a: i32,
    b: AllCopy,
    c: [i8; 3],
}

#[derive(Clone)]
enum Enum1 {
    A(AllCopy),
    B(NestCopy),
}

// EMIT_MIR clone_as_copy.clone_as_copy.PreCodegen.after.mir
fn clone_as_copy(v: &NestCopy) -> NestCopy {
    // CHECK-LABEL: fn clone_as_copy(
    // CHECK-NOT: = AllCopy { {{.*}} };
    // CHECK-NOT: = NestCopy { {{.*}} };
    // CHECK: _0 = copy (*_1);
    // CHECK: return;
    v.clone()
}

// FIXME: We can merge into exactly one assignment statement.
// EMIT_MIR clone_as_copy.enum_clone_as_copy.PreCodegen.after.mir
fn enum_clone_as_copy(v: &Enum1) -> Enum1 {
    // CHECK-LABEL: fn enum_clone_as_copy(
    // CHECK-NOT: = Enum1::
    // CHECK: _0 = copy (*_1);
    // CHECK: _0 = copy (*_1);
    v.clone()
}