]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/type-ascription.rs
Auto merge of #47203 - varkor:output-filename-conflicts-with-directory, r=estebank
[rust.git] / src / test / run-pass / type-ascription.rs
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.
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 // Type ascription doesn't lead to unsoundness
12
13 #![feature(type_ascription)]
14
15 use std::mem;
16
17 const C1: u8 = 10: u8;
18 const C2: [u8; 1: usize] = [1];
19
20 struct S {
21     a: u8
22 }
23
24 fn main() {
25     assert_eq!(C1.into(): i32, 10);
26     assert_eq!(C2[0], 1);
27
28     let s = S { a: 10: u8 };
29     let arr = &[1u8, 2, 3];
30
31     let mut v = arr.iter().cloned().collect(): Vec<_>;
32     v.push(4);
33     assert_eq!(v, [1, 2, 3, 4]);
34
35     let a = 1: u8;
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);
41
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]);
45 }