From a1fabbf3865c1044c7e96e8ac337131ebdf411b6 Mon Sep 17 00:00:00 2001 From: GambitingMan <68272188+GambitingMan@users.noreply.github.com> Date: Wed, 20 Sep 2023 21:29:02 +0200 Subject: [PATCH] Bugfix/comment duplication (#5913) * Fix #5871 * Only idempotence test is necessary * Update src/expr.rs Co-authored-by: Caleb Cartwright --------- Co-authored-by: Caleb Cartwright --- src/expr.rs | 2 +- tests/target/issue-5871.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/target/issue-5871.rs 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 + ) +}