@@ -41,7 +41,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
41
41
}
42
42
43
43
/// Check whether two statements are the same.
44
- pub fn eq_stmt ( & self , left : & Stmt , right : & Stmt ) -> bool {
44
+ pub fn eq_stmt ( & mut self , left : & Stmt , right : & Stmt ) -> bool {
45
45
match ( & left. node , & right. node ) {
46
46
( & StmtDecl ( ref l, _) , & StmtDecl ( ref r, _) ) => {
47
47
if let ( & DeclLocal ( ref l) , & DeclLocal ( ref r) ) = ( & l. node , & r. node ) {
@@ -58,12 +58,12 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
58
58
}
59
59
60
60
/// Check whether two blocks are the same.
61
- pub fn eq_block ( & self , left : & Block , right : & Block ) -> bool {
61
+ pub fn eq_block ( & mut self , left : & Block , right : & Block ) -> bool {
62
62
over ( & left. stmts , & right. stmts , |l, r| self . eq_stmt ( l, r) )
63
63
&& both ( & left. expr , & right. expr , |l, r| self . eq_expr ( l, r) )
64
64
}
65
65
66
- pub fn eq_expr ( & self , left : & Expr , right : & Expr ) -> bool {
66
+ pub fn eq_expr ( & mut self , left : & Expr , right : & Expr ) -> bool {
67
67
if self . ignore_fn && differing_macro_contexts ( left. span , right. span ) {
68
68
return false ;
69
69
}
@@ -144,20 +144,20 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
144
144
}
145
145
}
146
146
147
- fn eq_exprs ( & self , left : & P < [ Expr ] > , right : & P < [ Expr ] > ) -> bool {
147
+ fn eq_exprs ( & mut self , left : & P < [ Expr ] > , right : & P < [ Expr ] > ) -> bool {
148
148
over ( left, right, |l, r| self . eq_expr ( l, r) )
149
149
}
150
150
151
- fn eq_field ( & self , left : & Field , right : & Field ) -> bool {
151
+ fn eq_field ( & mut self , left : & Field , right : & Field ) -> bool {
152
152
left. name . node == right. name . node && self . eq_expr ( & left. expr , & right. expr )
153
153
}
154
154
155
- fn eq_lifetime ( & self , left : & Lifetime , right : & Lifetime ) -> bool {
155
+ fn eq_lifetime ( & mut self , left : & Lifetime , right : & Lifetime ) -> bool {
156
156
left. name == right. name
157
157
}
158
158
159
159
/// Check whether two patterns are the same.
160
- pub fn eq_pat ( & self , left : & Pat , right : & Pat ) -> bool {
160
+ pub fn eq_pat ( & mut self , left : & Pat , right : & Pat ) -> bool {
161
161
match ( & left. node , & right. node ) {
162
162
( & PatKind :: Box ( ref l) , & PatKind :: Box ( ref r) ) => self . eq_pat ( l, r) ,
163
163
( & PatKind :: TupleStruct ( ref lp, ref la, ls) , & PatKind :: TupleStruct ( ref rp, ref ra, rs) ) => {
@@ -184,7 +184,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
184
184
}
185
185
}
186
186
187
- fn eq_qpath ( & self , left : & QPath , right : & QPath ) -> bool {
187
+ fn eq_qpath ( & mut self , left : & QPath , right : & QPath ) -> bool {
188
188
match ( left, right) {
189
189
( & QPath :: Resolved ( ref lty, ref lpath) , & QPath :: Resolved ( ref rty, ref rpath) ) => {
190
190
both ( lty, rty, |l, r| self . eq_ty ( l, r) ) && self . eq_path ( lpath, rpath)
@@ -196,12 +196,12 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
196
196
}
197
197
}
198
198
199
- fn eq_path ( & self , left : & Path , right : & Path ) -> bool {
199
+ fn eq_path ( & mut self , left : & Path , right : & Path ) -> bool {
200
200
left. is_global ( ) == right. is_global ( )
201
201
&& over ( & left. segments , & right. segments , |l, r| self . eq_path_segment ( l, r) )
202
202
}
203
203
204
- fn eq_path_parameters ( & self , left : & PathParameters , right : & PathParameters ) -> bool {
204
+ fn eq_path_parameters ( & mut self , left : & PathParameters , right : & PathParameters ) -> bool {
205
205
if !( left. parenthesized || right. parenthesized ) {
206
206
over ( & left. lifetimes , & right. lifetimes , |l, r| self . eq_lifetime ( l, r) )
207
207
&& over ( & left. types , & right. types , |l, r| self . eq_ty ( l, r) )
@@ -218,7 +218,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
218
218
}
219
219
}
220
220
221
- fn eq_path_segment ( & self , left : & PathSegment , right : & PathSegment ) -> bool {
221
+ fn eq_path_segment ( & mut self , left : & PathSegment , right : & PathSegment ) -> bool {
222
222
// The == of idents doesn't work with different contexts,
223
223
// we have to be explicit about hygiene
224
224
if left. name . as_str ( ) != right. name . as_str ( ) {
@@ -231,12 +231,23 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
231
231
}
232
232
}
233
233
234
- fn eq_ty ( & self , left : & Ty , right : & Ty ) -> bool {
234
+ fn eq_ty ( & mut self , left : & Ty , right : & Ty ) -> bool {
235
235
match ( & left. node , & right. node ) {
236
236
( & TySlice ( ref l_vec) , & TySlice ( ref r_vec) ) => self . eq_ty ( l_vec, r_vec) ,
237
237
( & TyArray ( ref lt, ll_id) , & TyArray ( ref rt, rl_id) ) => {
238
- self . eq_ty ( lt, rt)
239
- && self . eq_expr ( & self . cx . tcx . hir . body ( ll_id) . value , & self . cx . tcx . hir . body ( rl_id) . value )
238
+ let full_table = self . tables ;
239
+
240
+ let mut celcx = constant_context ( self . cx , self . cx . tcx . body_tables ( ll_id) ) ;
241
+ self . tables = self . cx . tcx . body_tables ( ll_id) ;
242
+ let ll = celcx. expr ( & self . cx . tcx . hir . body ( ll_id) . value ) ;
243
+
244
+ let mut celcx = constant_context ( self . cx , self . cx . tcx . body_tables ( rl_id) ) ;
245
+ self . tables = self . cx . tcx . body_tables ( rl_id) ;
246
+ let rl = celcx. expr ( & self . cx . tcx . hir . body ( rl_id) . value ) ;
247
+
248
+ let eq_ty = self . eq_ty ( lt, rt) ;
249
+ self . tables = full_table;
250
+ eq_ty && ll == rl
240
251
} ,
241
252
( & TyPtr ( ref l_mut) , & TyPtr ( ref r_mut) ) => l_mut. mutbl == r_mut. mutbl && self . eq_ty ( & * l_mut. ty , & * r_mut. ty ) ,
242
253
( & TyRptr ( _, ref l_rmut) , & TyRptr ( _, ref r_rmut) ) => {
@@ -249,7 +260,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
249
260
}
250
261
}
251
262
252
- fn eq_type_binding ( & self , left : & TypeBinding , right : & TypeBinding ) -> bool {
263
+ fn eq_type_binding ( & mut self , left : & TypeBinding , right : & TypeBinding ) -> bool {
253
264
left. name == right. name && self . eq_ty ( & left. ty , & right. ty )
254
265
}
255
266
}
@@ -467,8 +478,10 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
467
478
let c: fn ( _, _) -> _ = ExprRepeat ;
468
479
c. hash ( & mut self . s ) ;
469
480
self . hash_expr ( e) ;
481
+ let full_table = self . tables ;
470
482
self . tables = self . cx . tcx . body_tables ( l_id) ;
471
483
self . hash_expr ( & self . cx . tcx . hir . body ( l_id) . value ) ;
484
+ self . tables = full_table;
472
485
} ,
473
486
ExprRet ( ref e) => {
474
487
let c: fn ( _) -> _ = ExprRet ;
0 commit comments