@@ -1071,17 +1071,31 @@ impl UnusedParens {
10711071 self . emit_unused_delims ( cx, value. span , spans, "pattern" , keep_space, false ) ;
10721072 }
10731073 }
1074+
1075+ fn cast_followed_by_lt ( & self , expr : & ast:: Expr ) -> Option < ast:: NodeId > {
1076+ if let ExprKind :: Binary ( op, lhs, _rhs) = & expr. kind
1077+ && ( op. node == ast:: BinOpKind :: Lt || op. node == ast:: BinOpKind :: Shl )
1078+ {
1079+ let mut cur = lhs;
1080+ while let ExprKind :: Binary ( _, _, rhs) = & cur. kind {
1081+ cur = rhs;
1082+ }
1083+
1084+ if let ExprKind :: Cast ( _, ty) = & cur. kind
1085+ && let ast:: TyKind :: Paren ( _) = & ty. kind
1086+ {
1087+ return Some ( ty. id ) ;
1088+ }
1089+ }
1090+ None
1091+ }
10741092}
10751093
10761094impl EarlyLintPass for UnusedParens {
10771095 #[ inline]
10781096 fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
1079- if let ExprKind :: Binary ( op, lhs, _rhs) = & e. kind
1080- && ( op. node == ast:: BinOpKind :: Lt || op. node == ast:: BinOpKind :: Shl )
1081- && let ExprKind :: Cast ( _expr, ty) = & lhs. kind
1082- && let ast:: TyKind :: Paren ( _) = & ty. kind
1083- {
1084- self . parens_in_cast_in_lt . push ( ty. id ) ;
1097+ if let Some ( ty_id) = self . cast_followed_by_lt ( e) {
1098+ self . parens_in_cast_in_lt . push ( ty_id) ;
10851099 }
10861100
10871101 match e. kind {
@@ -1131,17 +1145,13 @@ impl EarlyLintPass for UnusedParens {
11311145 }
11321146
11331147 fn check_expr_post ( & mut self , _cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
1134- if let ExprKind :: Binary ( op, lhs, _rhs) = & e. kind
1135- && ( op. node == ast:: BinOpKind :: Lt || op. node == ast:: BinOpKind :: Shl )
1136- && let ExprKind :: Cast ( _expr, ty) = & lhs. kind
1137- && let ast:: TyKind :: Paren ( _) = & ty. kind
1138- {
1148+ if let Some ( ty_id) = self . cast_followed_by_lt ( e) {
11391149 let id = self
11401150 . parens_in_cast_in_lt
11411151 . pop ( )
11421152 . expect ( "check_expr and check_expr_post must balance" ) ;
11431153 assert_eq ! (
1144- id, ty . id ,
1154+ id, ty_id ,
11451155 "check_expr, check_ty, and check_expr_post are called, in that order, by the visitor"
11461156 ) ;
11471157 }
0 commit comments