]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/vec-dst.rs
rollup merge of #18347 : cakebaker/ffi
[rust.git] / src / test / run-pass / vec-dst.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 fn sub_expr() {
12     // Test for a &[T] => &&[T] coercion in sub-expression position
13     // (surprisingly, this can cause errors which are not caused by either of:
14     //    `let x = vec.slice_mut(0, 2);`
15     //    `foo(vec.slice_mut(0, 2));` ).
16     let mut vec: Vec<int> = vec!(1, 2, 3, 4);
17     let b: &mut [int] = [1, 2];
18     assert!(vec.slice_mut(0, 2) == b);
19 }
20
21 fn index() {
22     // Tests for indexing into box/& [T, ..n]
23     let x: [int, ..3] = [1, 2, 3];
24     let mut x: Box<[int, ..3]> = box x;
25     assert!(x[0] == 1);
26     assert!(x[1] == 2);
27     assert!(x[2] == 3);
28     x[1] = 45;
29     assert!(x[0] == 1);
30     assert!(x[1] == 45);
31     assert!(x[2] == 3);
32
33     let mut x: [int, ..3] = [1, 2, 3];
34     let x: &mut [int, ..3] = &mut x;
35     assert!(x[0] == 1);
36     assert!(x[1] == 2);
37     assert!(x[2] == 3);
38     x[1] = 45;
39     assert!(x[0] == 1);
40     assert!(x[1] == 45);
41     assert!(x[2] == 3);
42 }
43
44 pub fn main() {
45     sub_expr();
46     index();
47 }