]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/ranges-precedence.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / ranges-precedence.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 // Test that the precedence of ranges is correct
12
13
14
15 struct Foo {
16     foo: usize,
17 }
18
19 impl Foo {
20     fn bar(&self) -> usize { 5 }
21 }
22
23 fn main() {
24     let x = 1+3..4+5;
25     assert_eq!(x, (4..9));
26
27     let x = 1..4+5;
28     assert_eq!(x, (1..9));
29
30     let x = 1+3..4;
31     assert_eq!(x, (4..4));
32
33     let a = Foo { foo: 3 };
34     let x = a.foo..a.bar();
35     assert_eq!(x, (3..5));
36
37     let x = 1+3..;
38     assert_eq!(x, (4..));
39     let x = ..1+3;
40     assert_eq!(x, (..4));
41
42     let a = &[0, 1, 2, 3, 4, 5, 6];
43     let x = &a[1+1..2+2];
44     assert_eq!(x, &a[2..4]);
45     let x = &a[..1+2];
46     assert_eq!(x, &a[..3]);
47     let x = &a[1+2..];
48     assert_eq!(x, &a[3..]);
49
50     for _i in 2+4..10-3 {}
51
52     let i = 42;
53     for _ in 1..i {}
54     for _ in 1.. { break; }
55
56     let x = [1]..[2];
57     assert_eq!(x, (([1])..([2])));
58
59     let y = ..;
60     assert_eq!(y, (..));
61 }