Do not check unused braces on inline consts
This commit is contained in:
parent
03defb627c
commit
547e5eb498
1 changed files with 56 additions and 21 deletions
|
@ -839,10 +839,6 @@ impl EarlyLintPass for UnusedParens {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_anon_const(&mut self, cx: &EarlyContext<'_>, c: &ast::AnonConst) {
|
|
||||||
self.check_unused_delims_expr(cx, &c.value, UnusedDelimsCtx::AnonConst, false, None, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
|
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
|
||||||
if let StmtKind::Local(ref local) = s.kind {
|
if let StmtKind::Local(ref local) = s.kind {
|
||||||
self.check_unused_parens_pat(cx, &local.pat, false, false);
|
self.check_unused_parens_pat(cx, &local.pat, false, false);
|
||||||
|
@ -965,13 +961,6 @@ impl UnusedDelimLint for UnusedBraces {
|
||||||
if !Self::is_expr_delims_necessary(expr, followed_by_block)
|
if !Self::is_expr_delims_necessary(expr, followed_by_block)
|
||||||
&& (ctx != UnusedDelimsCtx::AnonConst
|
&& (ctx != UnusedDelimsCtx::AnonConst
|
||||||
|| matches!(expr.kind, ast::ExprKind::Lit(_)))
|
|| matches!(expr.kind, ast::ExprKind::Lit(_)))
|
||||||
// array length expressions are checked during `check_anon_const` and `check_ty`,
|
|
||||||
// once as `ArrayLenExpr` and once as `AnonConst`.
|
|
||||||
//
|
|
||||||
// As we do not want to lint this twice, we do not emit an error for
|
|
||||||
// `ArrayLenExpr` if `AnonConst` would do the same.
|
|
||||||
&& (ctx != UnusedDelimsCtx::ArrayLenExpr
|
|
||||||
|| !matches!(expr.kind, ast::ExprKind::Lit(_)))
|
|
||||||
&& !cx.sess().source_map().is_multiline(value.span)
|
&& !cx.sess().source_map().is_multiline(value.span)
|
||||||
&& value.attrs.is_empty()
|
&& value.attrs.is_empty()
|
||||||
&& !value.span.from_expansion()
|
&& !value.span.from_expansion()
|
||||||
|
@ -999,21 +988,54 @@ impl UnusedDelimLint for UnusedBraces {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EarlyLintPass for UnusedBraces {
|
impl EarlyLintPass for UnusedBraces {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
|
||||||
<Self as UnusedDelimLint>::check_expr(self, cx, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_anon_const(&mut self, cx: &EarlyContext<'_>, c: &ast::AnonConst) {
|
|
||||||
self.check_unused_delims_expr(cx, &c.value, UnusedDelimsCtx::AnonConst, false, None, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
|
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
|
||||||
<Self as UnusedDelimLint>::check_stmt(self, cx, s)
|
<Self as UnusedDelimLint>::check_stmt(self, cx, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
||||||
|
<Self as UnusedDelimLint>::check_expr(self, cx, e);
|
||||||
|
|
||||||
|
if let ExprKind::Repeat(_, ref anon_const) = e.kind {
|
||||||
|
self.check_unused_delims_expr(
|
||||||
|
cx,
|
||||||
|
&anon_const.value,
|
||||||
|
UnusedDelimsCtx::AnonConst,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_generic_arg(&mut self, cx: &EarlyContext<'_>, arg: &ast::GenericArg) {
|
||||||
|
if let ast::GenericArg::Const(ct) = arg {
|
||||||
|
self.check_unused_delims_expr(
|
||||||
|
cx,
|
||||||
|
&ct.value,
|
||||||
|
UnusedDelimsCtx::AnonConst,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) {
|
||||||
|
if let Some(anon_const) = &v.disr_expr {
|
||||||
|
self.check_unused_delims_expr(
|
||||||
|
cx,
|
||||||
|
&anon_const.value,
|
||||||
|
UnusedDelimsCtx::AnonConst,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
||||||
if let &ast::TyKind::Paren(ref r) = &ty.kind {
|
match ty.kind {
|
||||||
if let ast::TyKind::Array(_, ref len) = r.kind {
|
ast::TyKind::Array(_, ref len) => {
|
||||||
self.check_unused_delims_expr(
|
self.check_unused_delims_expr(
|
||||||
cx,
|
cx,
|
||||||
&len.value,
|
&len.value,
|
||||||
|
@ -1023,6 +1045,19 @@ impl EarlyLintPass for UnusedBraces {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ast::TyKind::Typeof(ref anon_const) => {
|
||||||
|
self.check_unused_delims_expr(
|
||||||
|
cx,
|
||||||
|
&anon_const.value,
|
||||||
|
UnusedDelimsCtx::AnonConst,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue