File: operands.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 (48 lines) | stat: -rw-r--r-- 1,232 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
46
47
48
//@ compile-flags: -Z unpretty=stable-mir --crate-type lib -C panic=abort
//@ check-pass
//@ only-x86_64
//@ needs-unwind unwind edges are different with panic=abort
//! Check how stable mir pretty printer prints different operands and abort strategy.

pub fn operands(val: u8) {
    let array = [val; 10];
    let first = array[0];
    let last = array[10 - 1];
    assert_eq!(first, last);

    let reference = &first;
    let dereferenced = *reference;
    assert_eq!(dereferenced, first);

    let tuple = (first, last);
    let (first_again, _) = tuple;
    let first_again_again = tuple.0;
    assert_eq!(first_again, first_again_again);

    let length = array.len();
    let size_of = std::mem::size_of_val(&length);
    assert_eq!(length, size_of);
}

pub struct Dummy {
    c: char,
    i: i32,
}

pub enum Ctors {
    Unit,
    StructLike { d: Dummy },
    TupLike(bool),
}

pub fn more_operands() -> [Ctors; 3] {
    let dummy = Dummy { c: 'a', i: i32::MIN };
    let unit = Ctors::Unit;
    let struct_like = Ctors::StructLike { d: dummy };
    let tup_like = Ctors::TupLike(false);
    [unit, struct_like, tup_like]
}

pub fn closures(x: bool, z: bool) -> impl FnOnce(bool) -> bool {
    move |y: bool| (x ^ y) || z
}