]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/slice-2.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / slice-2.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 // Test slicing expressions on slices and Vecs.
12
13
14 fn main() {
15     let x: &[isize] = &[1, 2, 3, 4, 5];
16     let cmp: &[isize] = &[1, 2, 3, 4, 5];
17     assert_eq!(&x[..], cmp);
18     let cmp: &[isize] = &[3, 4, 5];
19     assert_eq!(&x[2..], cmp);
20     let cmp: &[isize] = &[1, 2, 3];
21     assert_eq!(&x[..3], cmp);
22     let cmp: &[isize] = &[2, 3, 4];
23     assert_eq!(&x[1..4], cmp);
24
25     let x: Vec<isize> = vec![1, 2, 3, 4, 5];
26     let cmp: &[isize] = &[1, 2, 3, 4, 5];
27     assert_eq!(&x[..], cmp);
28     let cmp: &[isize] = &[3, 4, 5];
29     assert_eq!(&x[2..], cmp);
30     let cmp: &[isize] = &[1, 2, 3];
31     assert_eq!(&x[..3], cmp);
32     let cmp: &[isize] = &[2, 3, 4];
33     assert_eq!(&x[1..4], cmp);
34
35     let x: &mut [isize] = &mut [1, 2, 3, 4, 5];
36     {
37         let cmp: &mut [isize] = &mut [1, 2, 3, 4, 5];
38         assert_eq!(&mut x[..], cmp);
39     }
40     {
41         let cmp: &mut [isize] = &mut [3, 4, 5];
42         assert_eq!(&mut x[2..], cmp);
43     }
44     {
45         let cmp: &mut [isize] = &mut [1, 2, 3];
46         assert_eq!(&mut x[..3], cmp);
47     }
48     {
49         let cmp: &mut [isize] = &mut [2, 3, 4];
50         assert_eq!(&mut x[1..4], cmp);
51     }
52
53     let mut x: Vec<isize> = vec![1, 2, 3, 4, 5];
54     {
55         let cmp: &mut [isize] = &mut [1, 2, 3, 4, 5];
56         assert_eq!(&mut x[..], cmp);
57     }
58     {
59         let cmp: &mut [isize] = &mut [3, 4, 5];
60         assert_eq!(&mut x[2..], cmp);
61     }
62     {
63         let cmp: &mut [isize] = &mut [1, 2, 3];
64         assert_eq!(&mut x[..3], cmp);
65     }
66     {
67         let cmp: &mut [isize] = &mut [2, 3, 4];
68         assert_eq!(&mut x[1..4], cmp);
69     }
70 }