1
1
use crate :: pp:: Breaks :: Inconsistent ;
2
- use crate :: pprust:: state:: { AnnNode , PrintState , State } ;
2
+ use crate :: pprust:: state:: delimited:: IterDelimited ;
3
+ use crate :: pprust:: state:: { AnnNode , PrintState , State , INDENT_UNIT } ;
3
4
4
5
use rustc_ast as ast;
5
6
use rustc_ast:: GenericBound ;
@@ -138,11 +139,10 @@ impl<'a> State<'a> {
138
139
self . end ( ) ; // end outer head-block
139
140
}
140
141
ast:: ItemKind :: Use ( ref tree) => {
141
- self . head ( visibility_qualified ( & item. vis , "use" ) ) ;
142
+ self . print_visibility ( & item. vis ) ;
143
+ self . word_nbsp ( "use" ) ;
142
144
self . print_use_tree ( tree) ;
143
145
self . word ( ";" ) ;
144
- self . end ( ) ; // end inner head-block
145
- self . end ( ) ; // end outer head-block
146
146
}
147
147
ast:: ItemKind :: Static ( ref ty, mutbl, ref body) => {
148
148
let def = ast:: Defaultness :: Final ;
@@ -615,8 +615,8 @@ impl<'a> State<'a> {
615
615
ast:: UseTreeKind :: Simple ( rename, ..) => {
616
616
self . print_path ( & tree. prefix , false , 0 ) ;
617
617
if let Some ( rename) = rename {
618
- self . space ( ) ;
619
- self . word_space ( "as" ) ;
618
+ self . nbsp ( ) ;
619
+ self . word_nbsp ( "as" ) ;
620
620
self . print_ident ( rename) ;
621
621
}
622
622
}
@@ -628,16 +628,36 @@ impl<'a> State<'a> {
628
628
self . word ( "*" ) ;
629
629
}
630
630
ast:: UseTreeKind :: Nested ( ref items) => {
631
- if tree. prefix . segments . is_empty ( ) {
632
- self . word ( "{" ) ;
633
- } else {
631
+ if !tree. prefix . segments . is_empty ( ) {
634
632
self . print_path ( & tree. prefix , false , 0 ) ;
635
- self . word ( "::{" ) ;
633
+ self . word ( "::" ) ;
634
+ }
635
+ if items. is_empty ( ) {
636
+ self . word ( "{}" ) ;
637
+ } else if items. len ( ) == 1 {
638
+ self . print_use_tree ( & items[ 0 ] . 0 ) ;
639
+ } else {
640
+ self . cbox ( INDENT_UNIT ) ;
641
+ self . word ( "{" ) ;
642
+ self . zerobreak ( ) ;
643
+ self . ibox ( 0 ) ;
644
+ for use_tree in items. iter ( ) . delimited ( ) {
645
+ self . print_use_tree ( & use_tree. 0 ) ;
646
+ if !use_tree. is_last {
647
+ self . word ( "," ) ;
648
+ if let ast:: UseTreeKind :: Nested ( _) = use_tree. 0 . kind {
649
+ self . hardbreak ( ) ;
650
+ } else {
651
+ self . space ( ) ;
652
+ }
653
+ }
654
+ }
655
+ self . end ( ) ;
656
+ self . trailing_comma ( ) ;
657
+ self . offset ( -INDENT_UNIT ) ;
658
+ self . word ( "}" ) ;
659
+ self . end ( ) ;
636
660
}
637
- self . commasep ( Inconsistent , & items, |this, & ( ref tree, _) | {
638
- this. print_use_tree ( tree)
639
- } ) ;
640
- self . word ( "}" ) ;
641
661
}
642
662
}
643
663
}
0 commit comments