File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ // run-pass
2+ //
3+ // At one time, the `==` operator (and other binary operators) did not
4+ // support subtyping during type checking, and would therefore require
5+ // LHS and RHS to be exactly identical--i.e. to have the same lifetimes.
6+ //
7+ // This was fixed in 1a7fb7dc78439a704f024609ce3dc0beb1386552.
8+
9+ #[ derive( Copy , Clone ) ]
10+ struct Input < ' a > {
11+ foo : & ' a u32
12+ }
13+
14+ impl < ' a > std:: cmp:: PartialEq < Input < ' a > > for Input < ' a > {
15+ fn eq ( & self , other : & Input < ' a > ) -> bool {
16+ self . foo == other. foo
17+ }
18+
19+ fn ne ( & self , other : & Input < ' a > ) -> bool {
20+ self . foo != other. foo
21+ }
22+ }
23+
24+
25+ fn check_equal < ' a , ' b > ( x : Input < ' a > , y : Input < ' b > ) -> bool {
26+ // Type checking error due to 'a != 'b prior to 1a7fb7dc78
27+ x == y
28+ }
29+
30+ fn main ( ) {
31+ let i = 1u32 ;
32+ let j = 1u32 ;
33+ let k = 2u32 ;
34+
35+ let input_i = Input { foo : & i } ;
36+ let input_j = Input { foo : & j } ;
37+ let input_k = Input { foo : & k } ;
38+ assert ! ( check_equal( input_i, input_i) ) ;
39+ assert ! ( check_equal( input_i, input_j) ) ;
40+ assert ! ( !check_equal( input_i, input_k) ) ;
41+ }
You can’t perform that action at this time.
0 commit comments