Graydon Hoare | d1affff | 2012-12-11 01:32:48 | [diff] [blame] | 1 | // Copyright 2012 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 | |
Patrick Walton | 142dbd6 | 2013-03-23 01:52:04 | [diff] [blame] | 11 | static x : [int, ..4] = [1,2,3,4]; |
Patrick Walton | 85c9fc6 | 2013-03-22 21:00:15 | [diff] [blame] | 12 | static p : int = x[2]; |
| 13 | static y : &'static [int] = &[1,2,3,4]; |
| 14 | static q : int = y[2]; |
Graydon Hoare | a0e3a2a | 2012-08-09 02:41:50 | [diff] [blame] | 15 | |
Tim Chevalier | 6d4907a | 2013-01-26 06:46:32 | [diff] [blame] | 16 | struct S {a: int, b: int} |
| 17 | |
Patrick Walton | 85c9fc6 | 2013-03-22 21:00:15 | [diff] [blame] | 18 | static s : S = S {a: 10, b: 20}; |
| 19 | static t : int = s.b; |
Graydon Hoare | a0e3a2a | 2012-08-09 02:41:50 | [diff] [blame] | 20 | |
Tim Chevalier | 6d4907a | 2013-01-26 06:46:32 | [diff] [blame] | 21 | struct K {a: int, b: int, c: D} |
| 22 | struct D { d: int, e: int } |
| 23 | |
Patrick Walton | 85c9fc6 | 2013-03-22 21:00:15 | [diff] [blame] | 24 | static k : K = K {a: 10, b: 20, c: D {d: 30, e: 40}}; |
| 25 | static m : int = k.c.e; |
Niko Matsakis | 5e36a99 | 2012-08-28 22:54:45 | [diff] [blame] | 26 | |
Graydon Hoare | 89c8ef7 | 2013-02-02 03:43:17 | [diff] [blame] | 27 | pub fn main() { |
Birunthan Mohanathas | 206ae57 | 2013-07-22 16:04:51 | [diff] [blame] | 28 | printfln!(p); |
| 29 | printfln!(q); |
| 30 | printfln!(t); |
Corey Richardson | cc57ca0 | 2013-05-19 02:02:45 | [diff] [blame] | 31 | assert_eq!(p, 3); |
| 32 | assert_eq!(q, 3); |
| 33 | assert_eq!(t, 20); |
Ben Striegel | ac81fff | 2012-10-10 04:28:04 | [diff] [blame] | 34 | } |