]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/const-block.rs
Remove Ty prefix from Ty{Adt|Array|Slice|RawPtr|Ref|FnDef|FnPtr|Dynamic|Closure|Gener...
[rust.git] / src / test / run-pass / const-block.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 #![allow(dead_code)]
13 #![allow(unused_unsafe)]
14
15 use std::marker::Sync;
16
17 struct Foo {
18     a: usize,
19     b: *const ()
20 }
21
22 unsafe impl Sync for Foo {}
23
24 fn foo<T>(a: T) -> T {
25     a
26 }
27
28 static BLOCK_INTEGRAL: usize = { 1 };
29 static BLOCK_EXPLICIT_UNIT: () = { () };
30 static BLOCK_IMPLICIT_UNIT: () = { };
31 static BLOCK_FLOAT: f64 = { 1.0 };
32 static BLOCK_ENUM: Option<usize> = { Some(100) };
33 static BLOCK_STRUCT: Foo = { Foo { a: 12, b: 0 as *const () } };
34 static BLOCK_UNSAFE: usize = unsafe { 1000 };
35
36 static BLOCK_FN_INFERRED: fn(usize) -> usize = { foo };
37
38 static BLOCK_FN: fn(usize) -> usize = { foo::<usize> };
39
40 static BLOCK_ENUM_CONSTRUCTOR: fn(usize) -> Option<usize> = { Some };
41
42 pub fn main() {
43     assert_eq!(BLOCK_INTEGRAL, 1);
44     assert_eq!(BLOCK_EXPLICIT_UNIT, ());
45     assert_eq!(BLOCK_IMPLICIT_UNIT, ());
46     assert_eq!(BLOCK_FLOAT, 1.0_f64);
47     assert_eq!(BLOCK_STRUCT.a, 12);
48     assert_eq!(BLOCK_STRUCT.b, 0 as *const ());
49     assert_eq!(BLOCK_ENUM, Some(100));
50     assert_eq!(BLOCK_UNSAFE, 1000);
51     assert_eq!(BLOCK_FN_INFERRED(300), 300);
52     assert_eq!(BLOCK_FN(300), 300);
53     assert_eq!(BLOCK_ENUM_CONSTRUCTOR(200), Some(200));
54 }