@@ -8,7 +8,7 @@ use rustc_hir::HirIdMap;
88use rustc_hir:: {
99 BinOpKind , Block , BodyId , Expr , ExprField , ExprKind , FnRetTy , GenericArg , GenericArgs , Guard , HirId ,
1010 InlineAsmOperand , Let , Lifetime , LifetimeName , ParamName , Pat , PatField , PatKind , Path , PathSegment , QPath , Stmt ,
11- StmtKind , Ty , TyKind , TypeBinding ,
11+ StmtKind , Ty , TyKind , TypeBinding , ArrayLen
1212} ;
1313use rustc_lexer:: { tokenize, TokenKind } ;
1414use rustc_lint:: LateContext ;
@@ -170,6 +170,14 @@ impl HirEqInterExpr<'_, '_, '_> {
170170 }
171171 }
172172
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+
173181 pub fn eq_body ( & mut self , left : BodyId , right : BodyId ) -> bool {
174182 let cx = self . inner . cx ;
175183 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<'_, '_, '_> {
194202 }
195203
196204 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 ) ,
199207 ) {
200208 ( & ExprKind :: AddrOf ( lb, l_mut, le) , & ExprKind :: AddrOf ( rb, r_mut, re) ) => {
201209 lb == rb && l_mut == r_mut && self . eq_expr ( le, re)
@@ -232,7 +240,7 @@ impl HirEqInterExpr<'_, '_, '_> {
232240 } ,
233241 ( & ExprKind :: Index ( la, li) , & ExprKind :: Index ( ra, ri) ) => self . eq_expr ( la, ra) && self . eq_expr ( li, ri) ,
234242 ( & 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) )
236244 } ,
237245 ( & ExprKind :: Let ( l) , & ExprKind :: Let ( r) ) => {
238246 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<'_, '_, '_> {
253261 ( & ExprKind :: MethodCall ( l_path, _, l_args, _) , & ExprKind :: MethodCall ( r_path, _, r_args, _) ) => {
254262 self . inner . allow_side_effects && self . eq_path_segment ( l_path, r_path) && self . eq_exprs ( l_args, r_args)
255263 } ,
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 )
258266 } ,
259267 ( & ExprKind :: Ret ( ref l) , & ExprKind :: Ret ( ref r) ) => both ( l, r, |l, r| self . eq_expr ( l, r) ) ,
260268 ( & ExprKind :: Path ( ref l) , & ExprKind :: Path ( ref r) ) => self . eq_qpath ( l, r) ,
@@ -391,8 +399,8 @@ impl HirEqInterExpr<'_, '_, '_> {
391399 fn eq_ty ( & mut self , left : & Ty < ' _ > , right : & Ty < ' _ > ) -> bool {
392400 match ( & left. kind , & right. kind ) {
393401 ( & 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 )
396404 } ,
397405 ( & TyKind :: Ptr ( ref l_mut) , & TyKind :: Ptr ( ref r_mut) ) => {
398406 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> {
714722 ExprKind :: ConstBlock ( ref l_id) => {
715723 self . hash_body ( l_id. body ) ;
716724 } ,
717- ExprKind :: Repeat ( e, ref l_id ) => {
725+ ExprKind :: Repeat ( e, len ) => {
718726 self . hash_expr ( e) ;
719- self . hash_body ( l_id . body ) ;
727+ self . hash_array_length ( len ) ;
720728 } ,
721729 ExprKind :: Ret ( ref e) => {
722730 if let Some ( e) = * e {
@@ -906,9 +914,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
906914 TyKind :: Slice ( ty) => {
907915 self . hash_ty ( ty) ;
908916 } ,
909- TyKind :: Array ( ty, anon_const ) => {
917+ & TyKind :: Array ( ty, len ) => {
910918 self . hash_ty ( ty) ;
911- self . hash_body ( anon_const . body ) ;
919+ self . hash_array_length ( len ) ;
912920 } ,
913921 TyKind :: Ptr ( ref mut_ty) => {
914922 self . hash_ty ( mut_ty. ty ) ;
@@ -953,6 +961,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
953961 }
954962 }
955963
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+
956971 pub fn hash_body ( & mut self , body_id : BodyId ) {
957972 // swap out TypeckResults when hashing a body
958973 let old_maybe_typeck_results = self . maybe_typeck_results . replace ( self . cx . tcx . typeck_body ( body_id) ) ;
0 commit comments