@@ -839,10 +839,6 @@ impl EarlyLintPass for UnusedParens {
839
839
}
840
840
}
841
841
842
- fn check_anon_const(&mut self, cx: &EarlyContext<'_>, c: &ast::AnonConst) {
843
- self.check_unused_delims_expr(cx, &c.value, UnusedDelimsCtx::AnonConst, false, None, None);
844
- }
845
-
846
842
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
847
843
if let StmtKind::Local(ref local) = s.kind {
848
844
self.check_unused_parens_pat(cx, &local.pat, false, false);
@@ -965,13 +961,6 @@ impl UnusedDelimLint for UnusedBraces {
965
961
if !Self::is_expr_delims_necessary(expr, followed_by_block)
966
962
&& (ctx != UnusedDelimsCtx::AnonConst
967
963
|| matches!(expr.kind, ast::ExprKind::Lit(_)))
968
- // array length expressions are checked during `check_anon_const` and `check_ty`,
969
- // once as `ArrayLenExpr` and once as `AnonConst`.
970
- //
971
- // As we do not want to lint this twice, we do not emit an error for
972
- // `ArrayLenExpr` if `AnonConst` would do the same.
973
- && (ctx != UnusedDelimsCtx::ArrayLenExpr
974
- || !matches!(expr.kind, ast::ExprKind::Lit(_)))
975
964
&& !cx.sess().source_map().is_multiline(value.span)
976
965
&& value.attrs.is_empty()
977
966
&& !value.span.from_expansion()
@@ -999,21 +988,54 @@ impl UnusedDelimLint for UnusedBraces {
999
988
}
1000
989
1001
990
impl EarlyLintPass for UnusedBraces {
991
+ fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
992
+ <Self as UnusedDelimLint>::check_stmt(self, cx, s)
993
+ }
994
+
1002
995
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
1003
- <Self as UnusedDelimLint>::check_expr(self, cx, e)
996
+ <Self as UnusedDelimLint>::check_expr(self, cx, e);
997
+
998
+ if let ExprKind::Repeat(_, ref anon_const) = e.kind {
999
+ self.check_unused_delims_expr(
1000
+ cx,
1001
+ &anon_const.value,
1002
+ UnusedDelimsCtx::AnonConst,
1003
+ false,
1004
+ None,
1005
+ None,
1006
+ );
1007
+ }
1004
1008
}
1005
1009
1006
- fn check_anon_const(&mut self, cx: &EarlyContext<'_>, c: &ast::AnonConst) {
1007
- self.check_unused_delims_expr(cx, &c.value, UnusedDelimsCtx::AnonConst, false, None, None);
1010
+ fn check_generic_arg(&mut self, cx: &EarlyContext<'_>, arg: &ast::GenericArg) {
1011
+ if let ast::GenericArg::Const(ct) = arg {
1012
+ self.check_unused_delims_expr(
1013
+ cx,
1014
+ &ct.value,
1015
+ UnusedDelimsCtx::AnonConst,
1016
+ false,
1017
+ None,
1018
+ None,
1019
+ );
1020
+ }
1008
1021
}
1009
1022
1010
- fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
1011
- <Self as UnusedDelimLint>::check_stmt(self, cx, s)
1023
+ fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) {
1024
+ if let Some(anon_const) = &v.disr_expr {
1025
+ self.check_unused_delims_expr(
1026
+ cx,
1027
+ &anon_const.value,
1028
+ UnusedDelimsCtx::AnonConst,
1029
+ false,
1030
+ None,
1031
+ None,
1032
+ );
1033
+ }
1012
1034
}
1013
1035
1014
1036
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
1015
- if let &ast::TyKind::Paren(ref r) = & ty.kind {
1016
- if let ast::TyKind::Array(_, ref len) = r.kind {
1037
+ match ty.kind {
1038
+ ast::TyKind::Array(_, ref len) => {
1017
1039
self.check_unused_delims_expr(
1018
1040
cx,
1019
1041
&len.value,
@@ -1023,6 +1045,19 @@ impl EarlyLintPass for UnusedBraces {
1023
1045
None,
1024
1046
);
1025
1047
}
1048
+
1049
+ ast::TyKind::Typeof(ref anon_const) => {
1050
+ self.check_unused_delims_expr(
1051
+ cx,
1052
+ &anon_const.value,
1053
+ UnusedDelimsCtx::AnonConst,
1054
+ false,
1055
+ None,
1056
+ None,
1057
+ );
1058
+ }
1059
+
1060
+ _ => {}
1026
1061
}
1027
1062
}
1028
1063
0 commit comments