mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user