summaryrefslogtreecommitdiffstats
path: root/src/test/ui/enum-discriminant/actually_not_an_enum-discriminant.rs
blob: 6a566ab3a3d88af022334229748a8b18ca414ea3 (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
// run-pass
#![feature(core_intrinsics)]

use std::intrinsics::discriminant_value;

struct Zst;

struct Struct {
    _a: u32,
}

union Union {
    _a: u32,
}

fn check(v: u8) {
    assert_eq!(v, 0);
}

pub fn generic<T>()
where
    for<'a> T: Fn(&'a isize),
{
    let v: Vec<T> =  Vec::new();
    let _: u8 = discriminant_value(&v);
}

fn main() {
    // check that we use `u8` as the discriminant value
    // for everything that is not an enum.
    check(discriminant_value(&true));
    check(discriminant_value(&'a'));
    check(discriminant_value(&7));
    check(discriminant_value(&7.0));
    check(discriminant_value(&Zst));
    check(discriminant_value(&Struct { _a: 7 }));
    check(discriminant_value(&Union { _a: 7 }));
    check(discriminant_value(&[7, 77]));
    check(discriminant_value(&(7 as *const ())));
    check(discriminant_value(&(7 as *mut ())));
    check(discriminant_value(&&7));
    check(discriminant_value(&&mut 7));
    check(discriminant_value(&check));
    let fn_ptr: fn(u8) = check;
    check(discriminant_value(&fn_ptr));
    let hrtb: for<'a> fn(&'a str) -> &'a str = |x| x;
    check(discriminant_value(&hrtb));
    check(discriminant_value(&(7, 77, 777)));
}