Skip to content

Commit fd5f8a1

Browse files
committed
gate the change on style edition 2024
1 parent c2fe0d8 commit fd5f8a1

7 files changed

+13
-6
lines changed

src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
224224
self.trim_spaces_after_opening_brace(b, inner_attrs);
225225

226226
// Try to detect comments that refer to the block, not the first statement in the block.
227-
if has_braces {
227+
if has_braces && self.config.style_edition() >= StyleEdition::Edition2024 {
228228
let block_line_range = self.psess.lookup_line_range(b.span);
229229
if block_line_range.lo != block_line_range.hi {
230230
// Skipping if a single line block

tests/source/issue-3255.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// rustfmt-style_edition: 2024
2+
13
fn foo(){
24
if true { // Sample comment
35
// second-line comment

tests/target/async_fn.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ async unsafe fn foo() {
1313
}
1414

1515
async unsafe fn rust() {
16-
async move { // comment
16+
async move {
17+
// comment
1718
Ok(())
1819
}
1920
}

tests/target/control-brace-style-always-next-line.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ fn main() {
2020
}
2121

2222
'while_label: while cond
23-
{ // while comment
23+
{
24+
// while comment
2425
();
2526
}
2627

tests/target/control-brace-style-always-same-line.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ fn main() {
1515
();
1616
}
1717

18-
'while_label: while cond { // while comment
18+
'while_label: while cond {
19+
// while comment
1920
();
2021
}
2122

tests/target/label_break.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ fn main() {
1919
// comment
2020
break 'block 1;
2121
}
22-
if bar() { /* comment */
22+
if bar() {
23+
/* comment */
2324
break 'block 2;
2425
}
2526
3

tests/target/match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ fn foo() {
77
// Some comment.
88
a => foo(),
99
b if 0 < 42 => foo(),
10-
c => { // Another comment.
10+
c => {
11+
// Another comment.
1112
// Comment.
1213
an_expression;
1314
foo()

0 commit comments

Comments
 (0)