File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## Unreleased
4
+
5
+ ### Bug fixes
6
+
7
+ - Fixed a bug where the formatter would move a comment before ` assert ` to be
8
+ after it.
9
+ ([ Giacomo Cavalieri] ( https://github.com/giacomocavalieri ) )
10
+
3
11
## v1.12.0-rc1 - 2025-07-18
4
12
5
13
### Compiler
Original file line number Diff line number Diff line change @@ -2573,14 +2573,16 @@ impl<'comments> Formatter<'comments> {
2573
2573
}
2574
2574
2575
2575
fn assert < ' a > ( & mut self , assert : & ' a UntypedAssert ) -> Document < ' a > {
2576
+ let comments = self . pop_comments ( assert. location . start ) ;
2577
+
2576
2578
let expression = if assert. value . is_binop ( ) || assert. value . is_pipeline ( ) {
2577
2579
self . expr ( & assert. value ) . nest ( INDENT )
2578
2580
} else {
2579
2581
self . expr ( & assert. value )
2580
2582
} ;
2581
2583
2582
2584
let doc = self . append_as_message ( expression, assert. message . as_ref ( ) ) ;
2583
- docvec ! [ "assert " , doc]
2585
+ commented ( docvec ! [ "assert " , doc] , comments )
2584
2586
}
2585
2587
2586
2588
fn bit_array < ' a > (
Original file line number Diff line number Diff line change @@ -6490,3 +6490,14 @@ fn assert_with_long_binary_expression() {
6490
6490
"#
6491
6491
) ;
6492
6492
}
6493
+
6494
+ #[ test]
6495
+ fn comment_is_not_moved_after_assert ( ) {
6496
+ assert_format ! (
6497
+ "pub fn main() {
6498
+ // Wibble!
6499
+ assert True
6500
+ }
6501
+ "
6502
+ ) ;
6503
+ }
You can’t perform that action at this time.
0 commit comments