Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,11 @@ pub(crate) fn rewrite_paren(
let remove_nested_parens = context.config.remove_nested_parens();
loop {
// 1 = "(" or ")"
pre_span = mk_sp(span.lo() + BytePos(1), subexpr.span.lo());
let expr_lo = subexpr
.attrs
.first()
.map_or(subexpr.span().lo(), |attr| attr.span.lo());
pre_span = mk_sp(span.lo() + BytePos(1), expr_lo);
post_span = mk_sp(subexpr.span.hi(), span.hi() - BytePos(1));
pre_comment = rewrite_missing_comment(pre_span, shape, context)?;
post_comment = rewrite_missing_comment(post_span, shape, context)?;
Expand Down
8 changes: 8 additions & 0 deletions tests/target/issue-5871.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(stmt_expr_attributes)]
fn okay() -> u32 {
(
// Comments in parentheses-expressions caused attributes to be duplicated.
#[allow(unused_variables)]
0
)
}