@@ -1953,7 +1953,7 @@ where
1953
1953
context. force_one_line_chain = true ;
1954
1954
}
1955
1955
}
1956
- last_arg_shape ( & context , item_vec, one_line_shape, args_max_width) . and_then ( |arg_shape| {
1956
+ last_arg_shape ( args , item_vec, one_line_shape, args_max_width) . and_then ( |arg_shape| {
1957
1957
rewrite_last_arg_with_overflow ( & context, args, & mut item_vec[ args. len ( ) - 1 ] , arg_shape)
1958
1958
} )
1959
1959
} else {
@@ -2000,26 +2000,32 @@ where
2000
2000
tactic
2001
2001
}
2002
2002
2003
- fn last_arg_shape (
2004
- context : & RewriteContext ,
2003
+ /// Returns a shape for the last argument which is going to be overflowed.
2004
+ fn last_arg_shape < T > (
2005
+ lists : & [ & T ] ,
2005
2006
items : & [ ListItem ] ,
2006
2007
shape : Shape ,
2007
2008
args_max_width : usize ,
2008
- ) -> Option < Shape > {
2009
- let overhead = items. iter ( ) . rev ( ) . skip ( 1 ) . fold ( 0 , |acc, i| {
2010
- acc + i. item . as_ref ( ) . map_or ( 0 , |s| first_line_width ( s) )
2009
+ ) -> Option < Shape >
2010
+ where
2011
+ T : Rewrite + Spanned + ToExpr ,
2012
+ {
2013
+ let is_nested_call = lists
2014
+ . iter ( )
2015
+ . next ( )
2016
+ . and_then ( |item| item. to_expr ( ) )
2017
+ . map_or ( false , is_nested_call) ;
2018
+ if items. len ( ) == 1 && !is_nested_call {
2019
+ return Some ( shape) ;
2020
+ }
2021
+ let offset = items. iter ( ) . rev ( ) . skip ( 1 ) . fold ( 0 , |acc, i| {
2022
+ // 2 = ", "
2023
+ acc + 2 + i. inner_as_ref ( ) . len ( )
2011
2024
} ) ;
2012
- let max_width = min ( args_max_width, shape. width ) ;
2013
- let arg_indent = if context. use_block_indent ( ) {
2014
- shape. block ( ) . indent . block_unindent ( context. config )
2015
- } else {
2016
- shape. block ( ) . indent
2017
- } ;
2018
- Some ( Shape {
2019
- width : max_width. checked_sub ( overhead) ?,
2020
- indent : arg_indent,
2021
- offset : 0 ,
2022
- } )
2025
+ Shape {
2026
+ width : min ( args_max_width, shape. width ) ,
2027
+ ..shape
2028
+ } . offset_left ( offset)
2023
2029
}
2024
2030
2025
2031
fn rewrite_last_arg_with_overflow < ' a , T > (
@@ -2101,6 +2107,18 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l
2101
2107
}
2102
2108
}
2103
2109
2110
+ fn is_nested_call ( expr : & ast:: Expr ) -> bool {
2111
+ match expr. node {
2112
+ ast:: ExprKind :: Call ( ..) | ast:: ExprKind :: Mac ( ..) => true ,
2113
+ ast:: ExprKind :: AddrOf ( _, ref expr)
2114
+ | ast:: ExprKind :: Box ( ref expr)
2115
+ | ast:: ExprKind :: Try ( ref expr)
2116
+ | ast:: ExprKind :: Unary ( _, ref expr)
2117
+ | ast:: ExprKind :: Cast ( ref expr, _) => is_nested_call ( expr) ,
2118
+ _ => false ,
2119
+ }
2120
+ }
2121
+
2104
2122
pub fn wrap_args_with_parens (
2105
2123
context : & RewriteContext ,
2106
2124
args_str : & str ,
0 commit comments