diff --git a/src/visitor.rs b/src/visitor.rs index dbae9e5f569..b57a49e502f 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -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 diff --git a/tests/source/issue-3255.rs b/tests/source/issue-3255.rs index 313e211ad61..fc54c0c5996 100644 --- a/tests/source/issue-3255.rs +++ b/tests/source/issue-3255.rs @@ -1,3 +1,5 @@ +// rustfmt-style_edition: 2024 + fn foo(){ if true { // Sample comment // second-line comment diff --git a/tests/target/async_fn.rs b/tests/target/async_fn.rs index 1bca39d5114..ac151dddb25 100644 --- a/tests/target/async_fn.rs +++ b/tests/target/async_fn.rs @@ -13,7 +13,8 @@ async unsafe fn foo() { } async unsafe fn rust() { - async move { // comment + async move { + // comment Ok(()) } } diff --git a/tests/target/control-brace-style-always-next-line.rs b/tests/target/control-brace-style-always-next-line.rs index cb82dff904b..054a3075ca0 100644 --- a/tests/target/control-brace-style-always-next-line.rs +++ b/tests/target/control-brace-style-always-next-line.rs @@ -20,7 +20,8 @@ fn main() { } 'while_label: while cond - { // while comment + { + // while comment (); } diff --git a/tests/target/control-brace-style-always-same-line.rs b/tests/target/control-brace-style-always-same-line.rs index 1b90505c9fb..cf3f82dfcf1 100644 --- a/tests/target/control-brace-style-always-same-line.rs +++ b/tests/target/control-brace-style-always-same-line.rs @@ -15,7 +15,8 @@ fn main() { (); } - 'while_label: while cond { // while comment + 'while_label: while cond { + // while comment (); } diff --git a/tests/target/issue-3255.rs b/tests/target/issue-3255.rs index a74a198fce2..1277a7f3751 100644 --- a/tests/target/issue-3255.rs +++ b/tests/target/issue-3255.rs @@ -1,3 +1,5 @@ +// rustfmt-style_edition: 2024 + fn foo() { if true { // Sample comment // second-line comment diff --git a/tests/target/label_break.rs b/tests/target/label_break.rs index 6f47f2a1b8c..728d78137c9 100644 --- a/tests/target/label_break.rs +++ b/tests/target/label_break.rs @@ -19,7 +19,8 @@ fn main() { // comment break 'block 1; } - if bar() { /* comment */ + if bar() { + /* comment */ break 'block 2; } 3 diff --git a/tests/target/match.rs b/tests/target/match.rs index e50554625bc..0e7815a814d 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -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()