@@ -1053,17 +1053,31 @@ impl UnusedParens {
1053
1053
self . emit_unused_delims ( cx, value. span , spans, "pattern" , keep_space, false ) ;
1054
1054
}
1055
1055
}
1056
+
1057
+ fn cast_followed_by_lt ( & self , e : & ast:: Expr ) -> Option < ast:: NodeId > {
1058
+ if let ExprKind :: Binary ( op, lhs, _rhs) = & e. kind
1059
+ && ( op. node == ast:: BinOpKind :: Lt || op. node == ast:: BinOpKind :: Shl )
1060
+ {
1061
+ let rhs_of_lhs = match & lhs. kind {
1062
+ ExprKind :: Binary ( _, _, rhs) => rhs,
1063
+ _ => lhs,
1064
+ } ;
1065
+
1066
+ if let ExprKind :: Cast ( _expr, ty) = & rhs_of_lhs. kind
1067
+ && let ast:: TyKind :: Paren ( _) = & ty. kind
1068
+ {
1069
+ return Some ( ty. id ) ;
1070
+ }
1071
+ }
1072
+ None
1073
+ }
1056
1074
}
1057
1075
1058
1076
impl EarlyLintPass for UnusedParens {
1059
1077
#[ inline]
1060
1078
fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
1061
- if let ExprKind :: Binary ( op, lhs, _rhs) = & e. kind
1062
- && ( op. node == ast:: BinOpKind :: Lt || op. node == ast:: BinOpKind :: Shl )
1063
- && let ExprKind :: Cast ( _expr, ty) = & lhs. kind
1064
- && let ast:: TyKind :: Paren ( _) = & ty. kind
1065
- {
1066
- self . parens_in_cast_in_lt . push ( ty. id ) ;
1079
+ if let Some ( ty_id) = self . cast_followed_by_lt ( e) {
1080
+ self . parens_in_cast_in_lt . push ( ty_id) ;
1067
1081
}
1068
1082
1069
1083
match e. kind {
@@ -1113,17 +1127,13 @@ impl EarlyLintPass for UnusedParens {
1113
1127
}
1114
1128
1115
1129
fn check_expr_post ( & mut self , _cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
1116
- if let ExprKind :: Binary ( op, lhs, _rhs) = & e. kind
1117
- && ( op. node == ast:: BinOpKind :: Lt || op. node == ast:: BinOpKind :: Shl )
1118
- && let ExprKind :: Cast ( _expr, ty) = & lhs. kind
1119
- && let ast:: TyKind :: Paren ( _) = & ty. kind
1120
- {
1130
+ if let Some ( ty_id) = self . cast_followed_by_lt ( e) {
1121
1131
let id = self
1122
1132
. parens_in_cast_in_lt
1123
1133
. pop ( )
1124
1134
. expect ( "check_expr and check_expr_post must balance" ) ;
1125
1135
assert_eq ! (
1126
- id, ty . id ,
1136
+ id, ty_id ,
1127
1137
"check_expr, check_ty, and check_expr_post are called, in that order, by the visitor"
1128
1138
) ;
1129
1139
}
0 commit comments