summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/building/custom/aggregate_exprs.rs
blob: 554c9c03ba4a007fe643068408c9d5de4104e406 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![feature(custom_mir, core_intrinsics)]

extern crate core;
use core::intrinsics::mir::*;

// EMIT_MIR aggregate_exprs.tuple.built.after.mir
#[custom_mir(dialect = "built")]
fn tuple() -> (i32, bool) {
    mir!(
        {
            RET = (1, true);
            Return()
        }
    )
}

// EMIT_MIR aggregate_exprs.array.built.after.mir
#[custom_mir(dialect = "built")]
fn array() -> [i32; 2] {
    mir!(
        let x: [i32; 2];
        let one: i32;
        {
            x = [42, 43];
            one = 1;
            x = [one, 2];
            RET = Move(x);
            Return()
        }
    )
}

struct Foo {
    a: i32,
    b: i32,
}

enum Bar {
    Foo(Foo, i32),
}

union Onion {
    neon: i32,
    noun: f32,
}

// EMIT_MIR aggregate_exprs.adt.built.after.mir
#[custom_mir(dialect = "built")]
fn adt() -> Onion {
    mir!(
        let one: i32;
        let x: Foo;
        let y: Bar;
        {
            one = 1;
            x = Foo {
                a: 1,
                b: 2,
            };
            y = Bar::Foo(Move(x), one);
            RET = Onion { neon: Field(Variant(y, 0), 1) };
            Return()
        }
    )
}

fn main() {
    assert_eq!(tuple(), (1, true));
    assert_eq!(array(), [1, 2]);
    assert_eq!(unsafe { adt().neon }, 1);
}