File tree Expand file tree Collapse file tree 4 files changed +17
-14
lines changed Expand file tree Collapse file tree 4 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -454,11 +454,19 @@ impl<'a> FmtVisitor<'a> {
454
454
455
455
if is_internal {
456
456
self . buffer . push_str ( " {" ) ;
457
- self . last_pos = :: utils:: span_after ( s, "{" , self . codemap ) ;
458
- self . block_indent = self . block_indent . block_indent ( self . config ) ;
459
- self . walk_mod_items ( m) ;
460
- self . format_missing_with_indent ( m. inner . hi - BytePos ( 1 ) ) ;
461
- self . close_block ( ) ;
457
+ // Hackery to account for the closing }.
458
+ let mod_lo = :: utils:: span_after ( s, "{" , self . codemap ) ;
459
+ let body_snippet = self . snippet ( codemap:: mk_sp ( mod_lo, m. inner . hi - BytePos ( 1 ) ) ) ;
460
+ let body_snippet = body_snippet. trim ( ) ;
461
+ if body_snippet. is_empty ( ) {
462
+ self . buffer . push_str ( "}" ) ;
463
+ } else {
464
+ self . last_pos = mod_lo;
465
+ self . block_indent = self . block_indent . block_indent ( self . config ) ;
466
+ self . walk_mod_items ( m) ;
467
+ self . format_missing_with_indent ( m. inner . hi - BytePos ( 1 ) ) ;
468
+ self . close_block ( ) ;
469
+ }
462
470
self . last_pos = m. inner . hi ;
463
471
} else {
464
472
self . buffer . push_str ( ";" ) ;
Original file line number Diff line number Diff line change 2
2
3
3
/// This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
4
4
/// and justly.
5
- pub mod foo {
6
- }
5
+ pub mod foo { }
Original file line number Diff line number Diff line change 3
3
//! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
4
4
//! and justly.
5
5
6
- pub mod foo {
7
- }
6
+ pub mod foo { }
Original file line number Diff line number Diff line change 2
2
3
3
mod foo {
4
4
mod bar {
5
- mod baz {
6
- }
5
+ mod baz { }
7
6
}
8
7
}
9
8
@@ -16,9 +15,7 @@ mod foo {
16
15
}
17
16
}
18
17
19
- mod qux {
20
-
21
- }
18
+ mod qux { }
22
19
}
23
20
24
21
mod boxed {
You can’t perform that action at this time.
0 commit comments