@@ -168,6 +168,12 @@ impl HirEqInterExpr<'_, '_, '_> {
168
168
}
169
169
}
170
170
171
+ pub fn eq_body ( & mut self , left : BodyId , right : BodyId ) -> bool {
172
+ let cx = self . inner . cx ;
173
+ let eval_const = |body| constant_context ( cx, cx. tcx . typeck_body ( body) ) . expr ( & cx. tcx . hir ( ) . body ( body) . value ) ;
174
+ eval_const ( left) == eval_const ( right)
175
+ }
176
+
171
177
#[ allow( clippy:: similar_names) ]
172
178
pub fn eq_expr ( & mut self , left : & Expr < ' _ > , right : & Expr < ' _ > ) -> bool {
173
179
if !self . inner . allow_side_effects && differing_macro_contexts ( left. span , right. span ) {
@@ -243,12 +249,7 @@ impl HirEqInterExpr<'_, '_, '_> {
243
249
self . inner . allow_side_effects && self . eq_path_segment ( l_path, r_path) && self . eq_exprs ( l_args, r_args)
244
250
} ,
245
251
( & ExprKind :: Repeat ( le, ref ll_id) , & ExprKind :: Repeat ( re, ref rl_id) ) => {
246
- let mut celcx = constant_context ( self . inner . cx , self . inner . cx . tcx . typeck_body ( ll_id. body ) ) ;
247
- let ll = celcx. expr ( & self . inner . cx . tcx . hir ( ) . body ( ll_id. body ) . value ) ;
248
- let mut celcx = constant_context ( self . inner . cx , self . inner . cx . tcx . typeck_body ( rl_id. body ) ) ;
249
- let rl = celcx. expr ( & self . inner . cx . tcx . hir ( ) . body ( rl_id. body ) . value ) ;
250
-
251
- self . eq_expr ( le, re) && ll == rl
252
+ self . eq_expr ( le, re) && self . eq_body ( ll_id. body , rl_id. body )
252
253
} ,
253
254
( & ExprKind :: Ret ( ref l) , & ExprKind :: Ret ( ref r) ) => both ( l, r, |l, r| self . eq_expr ( l, r) ) ,
254
255
( & ExprKind :: Path ( ref l) , & ExprKind :: Path ( ref r) ) => self . eq_qpath ( l, r) ,
@@ -284,6 +285,7 @@ impl HirEqInterExpr<'_, '_, '_> {
284
285
285
286
fn eq_generic_arg ( & mut self , left : & GenericArg < ' _ > , right : & GenericArg < ' _ > ) -> bool {
286
287
match ( left, right) {
288
+ ( GenericArg :: Const ( l) , GenericArg :: Const ( r) ) => self . eq_body ( l. value . body , r. value . body ) ,
287
289
( GenericArg :: Lifetime ( l_lt) , GenericArg :: Lifetime ( r_lt) ) => Self :: eq_lifetime ( l_lt, r_lt) ,
288
290
( GenericArg :: Type ( l_ty) , GenericArg :: Type ( r_ty) ) => self . eq_ty ( l_ty, r_ty) ,
289
291
_ => false ,
@@ -384,10 +386,7 @@ impl HirEqInterExpr<'_, '_, '_> {
384
386
match ( & left. kind , & right. kind ) {
385
387
( & TyKind :: Slice ( l_vec) , & TyKind :: Slice ( r_vec) ) => self . eq_ty ( l_vec, r_vec) ,
386
388
( & TyKind :: Array ( lt, ref ll_id) , & TyKind :: Array ( rt, ref rl_id) ) => {
387
- let cx = self . inner . cx ;
388
- let eval_const =
389
- |body| constant_context ( cx, cx. tcx . typeck_body ( body) ) . expr ( & cx. tcx . hir ( ) . body ( body) . value ) ;
390
- self . eq_ty ( lt, rt) && eval_const ( ll_id. body ) == eval_const ( rl_id. body )
389
+ self . eq_ty ( lt, rt) && self . eq_body ( ll_id. body , rl_id. body )
391
390
} ,
392
391
( & TyKind :: Ptr ( ref l_mut) , & TyKind :: Ptr ( ref r_mut) ) => {
393
392
l_mut. mutbl == r_mut. mutbl && self . eq_ty ( & * l_mut. ty , & * r_mut. ty )
@@ -837,6 +836,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
837
836
_ => {
838
837
for seg in path. segments {
839
838
self . hash_name ( seg. ident . name ) ;
839
+ self . hash_generic_args ( seg. args ( ) . args ) ;
840
840
}
841
841
} ,
842
842
}
0 commit comments