]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/ranges-precedence.rs
Rollup merge of #92399 - Veeupup:fix_vec_typo, r=Dylan-DPC
[rust.git] / src / test / ui / parser / ranges-precedence.rs
1 // run-pass
2 // Test that the precedence of ranges is correct
3
4
5
6 struct Foo {
7     foo: usize,
8 }
9
10 impl Foo {
11     fn bar(&self) -> usize { 5 }
12 }
13
14 fn main() {
15     let x = 1+3..4+5;
16     assert_eq!(x, (4..9));
17
18     let x = 1..4+5;
19     assert_eq!(x, (1..9));
20
21     let x = 1+3..4;
22     assert_eq!(x, (4..4));
23
24     let a = Foo { foo: 3 };
25     let x = a.foo..a.bar();
26     assert_eq!(x, (3..5));
27
28     let x = 1+3..;
29     assert_eq!(x, (4..));
30     let x = ..1+3;
31     assert_eq!(x, (..4));
32
33     let a = &[0, 1, 2, 3, 4, 5, 6];
34     let x = &a[1+1..2+2];
35     assert_eq!(x, &a[2..4]);
36     let x = &a[..1+2];
37     assert_eq!(x, &a[..3]);
38     let x = &a[1+2..];
39     assert_eq!(x, &a[3..]);
40
41     for _i in 2+4..10-3 {}
42
43     let i = 42;
44     for _ in 1..i {}
45     for _ in 1.. { break; }
46
47     let x = [1]..[2];
48     assert_eq!(x, (([1])..([2])));
49
50     let y = ..;
51     assert_eq!(y, (..));
52 }