Skip to content

Commit adaa756

Browse files
committed
Add more ranges parsing tests
--- stderr ------------------------------- error: expected expression, found `..` --> tests/ui/parser/ranges-precedence.rs:75:12 | LL | ($e:expr) => {}; | ------- while parsing argument for this `expr` macro fragment LL | } LL | expr!(!..0); | ^^ expected expression error: expected expression, found `..` --> tests/ui/parser/ranges-precedence.rs:76:12 | LL | ($e:expr) => {}; | ------- while parsing argument for this `expr` macro fragment ... LL | expr!(-..0); | ^^ expected expression error: expected expression, found `..` --> tests/ui/parser/ranges-precedence.rs:77:12 | LL | ($e:expr) => {}; | ------- while parsing argument for this `expr` macro fragment ... LL | expr!(*..0); | ^^ expected expression error: aborting due to 3 previous errors ------------------------------------------
1 parent 64feb9b commit adaa756

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/ui/parser/ranges-precedence.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//@ run-pass
2+
//@ edition: 2021
23
// Test that the precedence of ranges is correct
34

4-
5+
use core::ops::{Add, RangeTo};
56

67
struct Foo {
78
foo: usize,
@@ -11,6 +12,13 @@ impl Foo {
1112
fn bar(&self) -> usize { 5 }
1213
}
1314

15+
impl Add<RangeTo<usize>> for Foo {
16+
type Output = usize;
17+
fn add(self, range: RangeTo<usize>) -> Self::Output {
18+
self.foo + range.end
19+
}
20+
}
21+
1422
fn main() {
1523
let x = 1+3..4+5;
1624
assert_eq!(x, (4..9));
@@ -49,4 +57,22 @@ fn main() {
4957

5058
let y = ..;
5159
assert_eq!(y, (..));
60+
61+
let reference = &..0;
62+
assert_eq!(*reference, ..0);
63+
let reference2 = &&..0;
64+
assert_eq!(**reference2, ..0);
65+
66+
let closure = || ..0;
67+
assert_eq!(closure(), ..0);
68+
69+
let sum = Foo { foo: 3 } + ..4;
70+
assert_eq!(sum, 7);
71+
72+
macro_rules! expr {
73+
($e:expr) => {};
74+
}
75+
expr!(!..0);
76+
expr!(-..0);
77+
expr!(*..0);
5278
}

0 commit comments

Comments
 (0)