1 // Copyright 2015 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.
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.
11 // Type ascription doesn't lead to unsoundness
13 #![feature(type_ascription)]
17 const C1: u8 = 10: u8;
18 const C2: [u8; 1: usize] = [1];
25 assert_eq!(C1.into(): i32, 10);
28 let s = S { a: 10: u8 };
29 let arr = &[1u8, 2, 3];
31 let mut v = arr.iter().cloned().collect(): Vec<_>;
33 assert_eq!(v, [1, 2, 3, 4]);
36 let b = a.into(): u16;
37 assert_eq!(v[a.into(): usize], 2);
38 assert_eq!(mem::size_of_val(&a), 1);
39 assert_eq!(mem::size_of_val(&b), 2);
40 assert_eq!(b, 1: u16);
42 let mut v = Vec::new();
43 v: Vec<u8> = vec![1, 2, 3]; // Place expression type ascription
44 assert_eq!(v, [1u8, 2, 3]);