Skip to content

Commit

Permalink
Bugfix/comment duplication (#5913)
Browse files Browse the repository at this point in the history
* Fix #5871

* Only idempotence test is necessary

* Update src/expr.rs

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

---------

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
  • Loading branch information
GambitingMan and calebcartwright authored Sep 20, 2023
1 parent da7f678 commit a1fabbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
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
)
}

0 comments on commit a1fabbf

Please sign in to comment.