@@ -8,7 +8,7 @@ use rustc_hir::HirIdMap;
8
8
use rustc_hir:: {
9
9
BinOpKind , Block , BodyId , Expr , ExprField , ExprKind , FnRetTy , GenericArg , GenericArgs , Guard , HirId ,
10
10
InlineAsmOperand , Let , Lifetime , LifetimeName , ParamName , Pat , PatField , PatKind , Path , PathSegment , QPath , Stmt ,
11
- StmtKind , Ty , TyKind , TypeBinding ,
11
+ StmtKind , Ty , TyKind , TypeBinding , ArrayLen
12
12
} ;
13
13
use rustc_lexer:: { tokenize, TokenKind } ;
14
14
use rustc_lint:: LateContext ;
@@ -170,6 +170,14 @@ impl HirEqInterExpr<'_, '_, '_> {
170
170
}
171
171
}
172
172
173
+ pub fn eq_array_length ( & mut self , left : ArrayLen , right : ArrayLen ) -> bool {
174
+ match ( left, right) {
175
+ ( ArrayLen :: Infer ( ..) , ArrayLen :: Infer ( ..) ) => true ,
176
+ ( ArrayLen :: Body ( l_ct) , ArrayLen :: Body ( r_ct) ) => self . eq_body ( l_ct. body , r_ct. body ) ,
177
+ ( _, _) => false ,
178
+ }
179
+ }
180
+
173
181
pub fn eq_body ( & mut self , left : BodyId , right : BodyId ) -> bool {
174
182
let cx = self . inner . cx ;
175
183
let eval_const = |body| constant_context ( cx, cx. tcx . typeck_body ( body) ) . expr ( & cx. tcx . hir ( ) . body ( body) . value ) ;
@@ -194,8 +202,8 @@ impl HirEqInterExpr<'_, '_, '_> {
194
202
}
195
203
196
204
let is_eq = match (
197
- & reduce_exprkind ( self . inner . cx , & left. kind ) ,
198
- & reduce_exprkind ( self . inner . cx , & right. kind ) ,
205
+ reduce_exprkind ( self . inner . cx , & left. kind ) ,
206
+ reduce_exprkind ( self . inner . cx , & right. kind ) ,
199
207
) {
200
208
( & ExprKind :: AddrOf ( lb, l_mut, le) , & ExprKind :: AddrOf ( rb, r_mut, re) ) => {
201
209
lb == rb && l_mut == r_mut && self . eq_expr ( le, re)
@@ -232,7 +240,7 @@ impl HirEqInterExpr<'_, '_, '_> {
232
240
} ,
233
241
( & ExprKind :: Index ( la, li) , & ExprKind :: Index ( ra, ri) ) => self . eq_expr ( la, ra) && self . eq_expr ( li, ri) ,
234
242
( & ExprKind :: If ( lc, lt, ref le) , & ExprKind :: If ( rc, rt, ref re) ) => {
235
- self . eq_expr ( lc, rc) && self . eq_expr ( & * * lt, & * * rt) && both ( le, re, |l, r| self . eq_expr ( l, r) )
243
+ self . eq_expr ( lc, rc) && self . eq_expr ( lt, rt) && both ( le, re, |l, r| self . eq_expr ( l, r) )
236
244
} ,
237
245
( & ExprKind :: Let ( l) , & ExprKind :: Let ( r) ) => {
238
246
self . eq_pat ( l. pat , r. pat ) && both ( & l. ty , & r. ty , |l, r| self . eq_ty ( l, r) ) && self . eq_expr ( l. init , r. init )
@@ -253,8 +261,8 @@ impl HirEqInterExpr<'_, '_, '_> {
253
261
( & ExprKind :: MethodCall ( l_path, _, l_args, _) , & ExprKind :: MethodCall ( r_path, _, r_args, _) ) => {
254
262
self . inner . allow_side_effects && self . eq_path_segment ( l_path, r_path) && self . eq_exprs ( l_args, r_args)
255
263
} ,
256
- ( & ExprKind :: Repeat ( le, ref ll_id ) , & ExprKind :: Repeat ( re, ref rl_id ) ) => {
257
- self . eq_expr ( le, re) && self . eq_body ( ll_id . body , rl_id . body )
264
+ ( & ExprKind :: Repeat ( le, ll ) , & ExprKind :: Repeat ( re, rl ) ) => {
265
+ self . eq_expr ( le, re) && self . eq_array_length ( ll , rl )
258
266
} ,
259
267
( & ExprKind :: Ret ( ref l) , & ExprKind :: Ret ( ref r) ) => both ( l, r, |l, r| self . eq_expr ( l, r) ) ,
260
268
( & ExprKind :: Path ( ref l) , & ExprKind :: Path ( ref r) ) => self . eq_qpath ( l, r) ,
@@ -391,8 +399,8 @@ impl HirEqInterExpr<'_, '_, '_> {
391
399
fn eq_ty ( & mut self , left : & Ty < ' _ > , right : & Ty < ' _ > ) -> bool {
392
400
match ( & left. kind , & right. kind ) {
393
401
( & TyKind :: Slice ( l_vec) , & TyKind :: Slice ( r_vec) ) => self . eq_ty ( l_vec, r_vec) ,
394
- ( & TyKind :: Array ( lt, ref ll_id ) , & TyKind :: Array ( rt, ref rl_id ) ) => {
395
- self . eq_ty ( lt, rt) && self . eq_body ( ll_id . body , rl_id . body )
402
+ ( & TyKind :: Array ( lt, ll ) , & TyKind :: Array ( rt, rl ) ) => {
403
+ self . eq_ty ( lt, rt) && self . eq_array_length ( ll , rl )
396
404
} ,
397
405
( & TyKind :: Ptr ( ref l_mut) , & TyKind :: Ptr ( ref r_mut) ) => {
398
406
l_mut. mutbl == r_mut. mutbl && self . eq_ty ( & * l_mut. ty , & * r_mut. ty )
@@ -714,9 +722,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
714
722
ExprKind :: ConstBlock ( ref l_id) => {
715
723
self . hash_body ( l_id. body ) ;
716
724
} ,
717
- ExprKind :: Repeat ( e, ref l_id ) => {
725
+ ExprKind :: Repeat ( e, len ) => {
718
726
self . hash_expr ( e) ;
719
- self . hash_body ( l_id . body ) ;
727
+ self . hash_array_length ( len ) ;
720
728
} ,
721
729
ExprKind :: Ret ( ref e) => {
722
730
if let Some ( e) = * e {
@@ -906,9 +914,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
906
914
TyKind :: Slice ( ty) => {
907
915
self . hash_ty ( ty) ;
908
916
} ,
909
- TyKind :: Array ( ty, anon_const ) => {
917
+ & TyKind :: Array ( ty, len ) => {
910
918
self . hash_ty ( ty) ;
911
- self . hash_body ( anon_const . body ) ;
919
+ self . hash_array_length ( len ) ;
912
920
} ,
913
921
TyKind :: Ptr ( ref mut_ty) => {
914
922
self . hash_ty ( mut_ty. ty ) ;
@@ -953,6 +961,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
953
961
}
954
962
}
955
963
964
+ pub fn hash_array_length ( & mut self , length : ArrayLen ) {
965
+ match length {
966
+ ArrayLen :: Infer ( ..) => { }
967
+ ArrayLen :: Body ( anon_const) => self . hash_body ( anon_const. body ) ,
968
+ }
969
+ }
970
+
956
971
pub fn hash_body ( & mut self , body_id : BodyId ) {
957
972
// swap out TypeckResults when hashing a body
958
973
let old_maybe_typeck_results = self . maybe_typeck_results . replace ( self . cx . tcx . typeck_body ( body_id) ) ;
0 commit comments