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 ------------------------------------------
This commit is contained in:
parent
64feb9b502
commit
adaa756b55
1 changed files with 27 additions and 1 deletions
|
@ -1,7 +1,8 @@
|
|||
//@ run-pass
|
||||
//@ edition: 2021
|
||||
// Test that the precedence of ranges is correct
|
||||
|
||||
|
||||
use core::ops::{Add, RangeTo};
|
||||
|
||||
struct Foo {
|
||||
foo: usize,
|
||||
|
@ -11,6 +12,13 @@ impl Foo {
|
|||
fn bar(&self) -> usize { 5 }
|
||||
}
|
||||
|
||||
impl Add<RangeTo<usize>> for Foo {
|
||||
type Output = usize;
|
||||
fn add(self, range: RangeTo<usize>) -> Self::Output {
|
||||
self.foo + range.end
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 1+3..4+5;
|
||||
assert_eq!(x, (4..9));
|
||||
|
@ -49,4 +57,22 @@ fn main() {
|
|||
|
||||
let y = ..;
|
||||
assert_eq!(y, (..));
|
||||
|
||||
let reference = &..0;
|
||||
assert_eq!(*reference, ..0);
|
||||
let reference2 = &&..0;
|
||||
assert_eq!(**reference2, ..0);
|
||||
|
||||
let closure = || ..0;
|
||||
assert_eq!(closure(), ..0);
|
||||
|
||||
let sum = Foo { foo: 3 } + ..4;
|
||||
assert_eq!(sum, 7);
|
||||
|
||||
macro_rules! expr {
|
||||
($e:expr) => {};
|
||||
}
|
||||
expr!(!..0);
|
||||
expr!(-..0);
|
||||
expr!(*..0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue