File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
1
//@ run-pass
2
+ //@ edition: 2021
2
3
// Test that the precedence of ranges is correct
3
4
4
-
5
+ use core :: ops :: { Add , RangeTo } ;
5
6
6
7
struct Foo {
7
8
foo : usize ,
@@ -11,6 +12,13 @@ impl Foo {
11
12
fn bar ( & self ) -> usize { 5 }
12
13
}
13
14
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
+
14
22
fn main ( ) {
15
23
let x = 1 +3 ..4 +5 ;
16
24
assert_eq ! ( x, ( 4 ..9 ) ) ;
@@ -49,4 +57,22 @@ fn main() {
49
57
50
58
let y = ..;
51
59
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 ) ;
52
78
}
You can’t perform that action at this time.
0 commit comments