diff options
| author | surechen <chenshuo17@huawei.com> | 2024-04-01 14:44:52 +0800 |
|---|---|---|
| committer | surechen <chenshuo17@huawei.com> | 2024-04-10 17:56:43 +0800 |
| commit | c8490a06085acf60bef4888d8af02c63fa0417d4 (patch) | |
| tree | e7bfb9f6310bbe29353dd01469ffed2ad59b06a3 /compiler | |
| parent | b14d8b2ef20c64c1002e2c6c724025c3d0846b91 (diff) | |
| download | rust-c8490a06085acf60bef4888d8af02c63fa0417d4.tar.gz rust-c8490a06085acf60bef4888d8af02c63fa0417d4.zip | |
skip `unused_parens`'s suggestion for `Paren` in macro.
fixes #120642
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 111a4fdcea1..503caa35358 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1074,10 +1074,14 @@ impl UnusedParens { // Otherwise proceed with linting. _ => {} } - let spans = inner - .span - .find_ancestor_inside(value.span) - .map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi()))); + let spans = if !value.span.from_expansion() { + inner + .span + .find_ancestor_inside(value.span) + .map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi()))) + } else { + None + }; self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space, false); } } @@ -1233,11 +1237,13 @@ impl EarlyLintPass for UnusedParens { if self.with_self_ty_parens && b.generic_params.len() > 0 => {} ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {} _ => { - let spans = r - .span - .find_ancestor_inside(ty.span) - .map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi()))); - + let spans = if !ty.span.from_expansion() { + r.span + .find_ancestor_inside(ty.span) + .map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi()))) + } else { + None + }; self.emit_unused_delims(cx, ty.span, spans, "type", (false, false), false); } } |
