File tree 3 files changed +17
-7
lines changed
3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ pub enum DefinitiveListTactic {
19
19
Vertical ,
20
20
Horizontal ,
21
21
Mixed ,
22
+ /// Tactic for nested import.
23
+ NestedImport ,
22
24
/// Special case tactic for `format!()`, `write!()` style macros.
23
25
SpecialMacro ( usize ) ,
24
26
}
Original file line number Diff line number Diff line change @@ -706,12 +706,16 @@ fn rewrite_nested_use_tree(
706
706
shape. width . saturating_sub ( 2 )
707
707
} ;
708
708
709
- let tactic = definitive_tactic (
710
- & list_items,
711
- context. config . imports_layout ( ) ,
712
- Separator :: Comma ,
713
- remaining_width,
714
- ) ;
709
+ let tactic = if has_nested_list {
710
+ DefinitiveListTactic :: NestedImport
711
+ } else {
712
+ definitive_tactic (
713
+ & list_items,
714
+ context. config . imports_layout ( ) ,
715
+ Separator :: Comma ,
716
+ remaining_width,
717
+ )
718
+ } ;
715
719
716
720
let ends_with_newline = context. config . imports_indent ( ) == IndentStyle :: Block
717
721
&& tactic != DefinitiveListTactic :: Horizontal ;
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ where
229
229
let sep_place =
230
230
SeparatorPlace :: from_tactic ( formatting. separator_place , tactic, formatting. separator ) ;
231
231
let mut prev_item_had_post_comment = false ;
232
+ let mut prev_item_is_nested_import = false ;
232
233
233
234
let mut line_len = 0 ;
234
235
let indent_str = & formatting. shape . indent . to_string ( formatting. config ) ;
@@ -281,12 +282,14 @@ where
281
282
result. push ( '\n' ) ;
282
283
result. push_str ( indent_str) ;
283
284
}
284
- DefinitiveListTactic :: Mixed => {
285
+ DefinitiveListTactic :: Mixed | DefinitiveListTactic :: NestedImport => {
285
286
let total_width = total_item_width ( item) + item_sep_len;
286
287
287
288
// 1 is space between separator and item.
288
289
if ( line_len > 0 && line_len + 1 + total_width > formatting. shape . width )
289
290
|| prev_item_had_post_comment
291
+ || ( tactic == DefinitiveListTactic :: NestedImport
292
+ && ( prev_item_is_nested_import || ( !first && inner_item. contains ( "::" ) ) ) )
290
293
{
291
294
result. push ( '\n' ) ;
292
295
result. push_str ( indent_str) ;
@@ -452,6 +455,7 @@ where
452
455
}
453
456
454
457
prev_item_had_post_comment = item. post_comment . is_some ( ) ;
458
+ prev_item_is_nested_import = inner_item. contains ( "::" ) ;
455
459
}
456
460
457
461
Some ( result)
You can’t perform that action at this time.
0 commit comments