2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
2015-01-07 19:30:33 +00:00
|
|
|
// Test that the precedence of ranges is correct
|
|
|
|
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-01-07 19:30:33 +00:00
|
|
|
struct Foo {
|
2015-03-26 00:06:52 +00:00
|
|
|
foo: usize,
|
2015-01-07 19:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn bar(&self) -> usize { 5 }
|
2015-01-07 19:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = 1+3..4+5;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (4..9));
|
2015-01-07 19:30:33 +00:00
|
|
|
|
|
|
|
let x = 1..4+5;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (1..9));
|
2015-01-07 19:30:33 +00:00
|
|
|
|
|
|
|
let x = 1+3..4;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (4..4));
|
2015-01-08 01:33:57 +00:00
|
|
|
|
2015-01-07 19:30:33 +00:00
|
|
|
let a = Foo { foo: 3 };
|
|
|
|
let x = a.foo..a.bar();
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (3..5));
|
2015-01-07 19:30:33 +00:00
|
|
|
|
|
|
|
let x = 1+3..;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (4..));
|
2015-01-07 19:30:33 +00:00
|
|
|
let x = ..1+3;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (..4));
|
2015-01-07 19:30:33 +00:00
|
|
|
|
2015-03-03 08:42:26 +00:00
|
|
|
let a = &[0, 1, 2, 3, 4, 5, 6];
|
2015-01-07 19:30:33 +00:00
|
|
|
let x = &a[1+1..2+2];
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, &a[2..4]);
|
2015-01-07 19:30:33 +00:00
|
|
|
let x = &a[..1+2];
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, &a[..3]);
|
2015-01-07 19:30:33 +00:00
|
|
|
let x = &a[1+2..];
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, &a[3..]);
|
2015-01-07 19:30:33 +00:00
|
|
|
|
|
|
|
for _i in 2+4..10-3 {}
|
2015-01-18 20:43:03 +00:00
|
|
|
|
|
|
|
let i = 42;
|
|
|
|
for _ in 1..i {}
|
|
|
|
for _ in 1.. { break; }
|
|
|
|
|
|
|
|
let x = [1]..[2];
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(x, (([1])..([2])));
|
2015-02-04 22:23:12 +00:00
|
|
|
|
|
|
|
let y = ..;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(y, (..));
|
2015-01-07 19:30:33 +00:00
|
|
|
}
|