diff options
Diffstat (limited to 'tests/ui/enum-discriminant/actually_not_an_enum-discriminant.rs')
-rw-r--r-- | tests/ui/enum-discriminant/actually_not_an_enum-discriminant.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/ui/enum-discriminant/actually_not_an_enum-discriminant.rs b/tests/ui/enum-discriminant/actually_not_an_enum-discriminant.rs new file mode 100644 index 000000000..6a566ab3a --- /dev/null +++ b/tests/ui/enum-discriminant/actually_not_an_enum-discriminant.rs @@ -0,0 +1,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))); +} |