File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 11//@ run-pass
2+ //@ edition: 2021
23// Test that the precedence of ranges is correct
34
4-
5+ use core :: ops :: { Add , RangeTo } ;
56
67struct 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+
1422fn 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}
You can’t perform that action at this time.
0 commit comments