diff --git a/src/expr.rs b/src/expr.rs index 450f1476db0..2f230ecc3b4 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1453,7 +1453,7 @@ 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()); + pre_span = mk_sp(span.lo() + BytePos(1), subexpr.span().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)?; diff --git a/tests/target/issue-5871.rs b/tests/target/issue-5871.rs new file mode 100644 index 00000000000..3116533bcb8 --- /dev/null +++ b/tests/target/issue-5871.rs @@ -0,0 +1,8 @@ +#![feature(stmt_expr_attributes)] +fn okay() -> u32 { + ( + // Comments in parentheses-expressions caused attributes to be duplicated. + #[allow(unused_variables)] + 0 + ) +}