Make unused_parens's suggestion considering expr's attributes
For the expr with attributes, like `let _ = (#[inline] || println!("Hello!"));`, the suggestion's span should contains the attributes, or the suggestion will remove them. fixes #129833
This commit is contained in:
parent
1b5aa96d60
commit
1e8d6d1ec3
4 changed files with 70 additions and 1 deletions
|
@ -804,7 +804,15 @@ trait UnusedDelimLint {
|
|||
.find_ancestor_inside(value.span)
|
||||
.map(|span| (value.span.with_hi(span.lo()), value.span.with_lo(span.hi()))),
|
||||
ast::ExprKind::Paren(ref expr) => {
|
||||
expr.span.find_ancestor_inside(value.span).map(|expr_span| {
|
||||
// For the expr with attributes, like `let _ = (#[inline] || println!("Hello!"));`,
|
||||
// the span should contains the attributes, or the suggestion will remove them.
|
||||
let expr_span_with_attrs =
|
||||
if let Some(attr_lo) = expr.attrs.iter().map(|attr| attr.span.lo()).min() {
|
||||
expr.span.with_lo(attr_lo)
|
||||
} else {
|
||||
expr.span
|
||||
};
|
||||
expr_span_with_attrs.find_ancestor_inside(value.span).map(|expr_span| {
|
||||
(value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi()))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue