Skip to content

Commit

Permalink
gate the change on style edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 7, 2024
1 parent c2fe0d8 commit 8595fbb
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.trim_spaces_after_opening_brace(b, inner_attrs);

// Try to detect comments that refer to the block, not the first statement in the block.
if has_braces {
if has_braces && self.config.style_edition() >= StyleEdition::Edition2024 {
let block_line_range = self.psess.lookup_line_range(b.span);
if block_line_range.lo != block_line_range.hi {
// Skipping if a single line block
Expand Down
2 changes: 2 additions & 0 deletions tests/source/issue-3255.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// rustfmt-style_edition: 2024

fn foo(){
if true { // Sample comment
// second-line comment
Expand Down
3 changes: 2 additions & 1 deletion tests/target/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ async unsafe fn foo() {
}

async unsafe fn rust() {
async move { // comment
async move {
// comment
Ok(())
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/target/control-brace-style-always-next-line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ fn main() {
}

'while_label: while cond
{ // while comment
{
// while comment
();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/target/control-brace-style-always-same-line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ fn main() {
();
}

'while_label: while cond { // while comment
'while_label: while cond {
// while comment
();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/target/issue-3255.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// rustfmt-style_edition: 2024

fn foo() {
if true { // Sample comment
// second-line comment
Expand Down
3 changes: 2 additions & 1 deletion tests/target/label_break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ fn main() {
// comment
break 'block 1;
}
if bar() { /* comment */
if bar() {
/* comment */
break 'block 2;
}
3
Expand Down
3 changes: 2 additions & 1 deletion tests/target/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fn foo() {
// Some comment.
a => foo(),
b if 0 < 42 => foo(),
c => { // Another comment.
c => {
// Another comment.
// Comment.
an_expression;
foo()
Expand Down

0 comments on commit 8595fbb

Please sign in to comment.