File tree 3 files changed +20
-8
lines changed
rustc_ast_pretty/src/pprust
3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -2460,7 +2460,11 @@ impl<'a> State<'a> {
2460
2460
self . print_path ( path, true , 0 ) ;
2461
2461
}
2462
2462
self . nbsp ( ) ;
2463
- self . word_space ( "{" ) ;
2463
+ self . word ( "{" ) ;
2464
+ let empty = fields. is_empty ( ) && !etc;
2465
+ if !empty {
2466
+ self . space ( ) ;
2467
+ }
2464
2468
self . commasep_cmnt (
2465
2469
Consistent ,
2466
2470
& fields,
@@ -2481,7 +2485,9 @@ impl<'a> State<'a> {
2481
2485
}
2482
2486
self . word ( ".." ) ;
2483
2487
}
2484
- self . space ( ) ;
2488
+ if !empty {
2489
+ self . space ( ) ;
2490
+ }
2485
2491
self . word ( "}" ) ;
2486
2492
}
2487
2493
PatKind :: Tuple ( ref elts) => {
Original file line number Diff line number Diff line change @@ -1874,7 +1874,11 @@ impl<'a> State<'a> {
1874
1874
PatKind :: Struct ( ref qpath, ref fields, etc) => {
1875
1875
self . print_qpath ( qpath, true ) ;
1876
1876
self . nbsp ( ) ;
1877
- self . word_space ( "{" ) ;
1877
+ self . word ( "{" ) ;
1878
+ let empty = fields. is_empty ( ) && !etc;
1879
+ if !empty {
1880
+ self . space ( ) ;
1881
+ }
1878
1882
self . commasep_cmnt (
1879
1883
Consistent ,
1880
1884
& fields,
@@ -1895,7 +1899,9 @@ impl<'a> State<'a> {
1895
1899
}
1896
1900
self . word ( ".." ) ;
1897
1901
}
1898
- self . space ( ) ;
1902
+ if !empty {
1903
+ self . space ( ) ;
1904
+ }
1899
1905
self . word ( "}" ) ;
1900
1906
}
1901
1907
PatKind :: Or ( ref pats) => {
Original file line number Diff line number Diff line change @@ -661,9 +661,9 @@ fn test_pat() {
661
661
assert_eq ! ( stringify_pat!( ref mut _x @ _) , "ref mut _x @ _" ) ;
662
662
663
663
// PatKind::Struct
664
- assert_eq ! ( stringify_pat!( Struct { } ) , "Struct { }" ) ; // FIXME
665
- assert_eq ! ( stringify_pat!( Struct :: <u8 > { } ) , "Struct::<u8> { }" ) ;
666
- assert_eq ! ( stringify_pat!( Struct :: <' static > { } ) , "Struct::<'static> { }" ) ;
664
+ assert_eq ! ( stringify_pat!( Struct { } ) , "Struct {}" ) ;
665
+ assert_eq ! ( stringify_pat!( Struct :: <u8 > { } ) , "Struct::<u8> {}" ) ;
666
+ assert_eq ! ( stringify_pat!( Struct :: <' static > { } ) , "Struct::<'static> {}" ) ;
667
667
assert_eq ! ( stringify_pat!( Struct { x } ) , "Struct { x }" ) ;
668
668
assert_eq ! ( stringify_pat!( Struct { x: _x } ) , "Struct { x: _x }" ) ;
669
669
assert_eq ! ( stringify_pat!( Struct { .. } ) , "Struct { .. }" ) ;
@@ -672,7 +672,7 @@ fn test_pat() {
672
672
#[ rustfmt:: skip] // https://github.com/rust-lang/rustfmt/issues/5151
673
673
assert_eq ! (
674
674
stringify_pat!( <Struct as Trait >:: Type { } ) ,
675
- "<Struct as Trait>::Type { }" ,
675
+ "<Struct as Trait>::Type {}" ,
676
676
) ;
677
677
678
678
// PatKind::TupleStruct
You can’t perform that action at this time.
0 commit comments