]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/const-block.rs
Rollup merge of #106951 - tmiasko:rm-simplify-initial, r=oli-obk
[rust.git] / tests / ui / consts / const-block.rs
1 // run-pass
2 #![allow(unused_braces)]
3 #![allow(dead_code)]
4 #![allow(unused_unsafe)]
5
6 use std::marker::Sync;
7
8 struct Foo {
9     a: usize,
10     b: *const ()
11 }
12
13 unsafe impl Sync for Foo {}
14
15 fn foo<T>(a: T) -> T {
16     a
17 }
18
19 static BLOCK_INTEGRAL: usize = { 1 };
20 static BLOCK_EXPLICIT_UNIT: () = { () };
21 static BLOCK_IMPLICIT_UNIT: () = { };
22 static BLOCK_FLOAT: f64 = { 1.0 };
23 static BLOCK_ENUM: Option<usize> = { Some(100) };
24 static BLOCK_STRUCT: Foo = { Foo { a: 12, b: std::ptr::null::<()>() } };
25 static BLOCK_UNSAFE: usize = unsafe { 1000 };
26
27 static BLOCK_FN_INFERRED: fn(usize) -> usize = { foo };
28
29 static BLOCK_FN: fn(usize) -> usize = { foo::<usize> };
30
31 static BLOCK_ENUM_CONSTRUCTOR: fn(usize) -> Option<usize> = { Some };
32
33 pub fn main() {
34     assert_eq!(BLOCK_INTEGRAL, 1);
35     assert_eq!(BLOCK_EXPLICIT_UNIT, ());
36     assert_eq!(BLOCK_IMPLICIT_UNIT, ());
37     assert_eq!(BLOCK_FLOAT, 1.0_f64);
38     assert_eq!(BLOCK_STRUCT.a, 12);
39     assert_eq!(BLOCK_STRUCT.b, std::ptr::null::<()>());
40     assert_eq!(BLOCK_ENUM, Some(100));
41     assert_eq!(BLOCK_UNSAFE, 1000);
42     assert_eq!(BLOCK_FN_INFERRED(300), 300);
43     assert_eq!(BLOCK_FN(300), 300);
44     assert_eq!(BLOCK_ENUM_CONSTRUCTOR(200), Some(200));
45 }