@@ -2042,42 +2042,27 @@ where
2042
2042
tactic = DefinitiveListTactic :: Horizontal ;
2043
2043
} else {
2044
2044
tactic = default_tactic ( ) ;
2045
- let is_simple_enough =
2046
- tactic == DefinitiveListTactic :: Vertical && is_every_args_simple ( args) ;
2047
- if is_simple_enough
2048
- && FORMAT_LIKE_WHITELIST
2049
- . iter ( )
2050
- . find ( |s| * * s == callee_str)
2051
- . is_some ( )
2052
- {
2053
- let args_tactic = definitive_tactic (
2054
- & item_vec[ 1 ..] ,
2055
- ListTactic :: HorizontalVertical ,
2056
- Separator :: Comma ,
2057
- nested_shape. width ,
2058
- ) ;
2059
- tactic = if args_tactic == DefinitiveListTactic :: Horizontal {
2060
- DefinitiveListTactic :: FormatCall
2061
- } else {
2062
- default_tactic ( )
2063
- } ;
2064
- } else if is_simple_enough && item_vec. len ( ) >= 2
2065
- && WRITE_LIKE_WHITELIST
2066
- . iter ( )
2067
- . find ( |s| * * s == callee_str)
2068
- . is_some ( )
2069
- {
2045
+
2046
+ // For special-case macros, we may want to use different tactics.
2047
+ let maybe_args_offset = maybe_get_args_offset ( callee_str, args) ;
2048
+
2049
+ if tactic == DefinitiveListTactic :: Vertical && maybe_args_offset. is_some ( ) {
2050
+ let args_offset = maybe_args_offset. unwrap ( ) ;
2070
2051
let args_tactic = definitive_tactic (
2071
- & item_vec[ 2 ..] ,
2052
+ & item_vec[ args_offset ..] ,
2072
2053
ListTactic :: HorizontalVertical ,
2073
2054
Separator :: Comma ,
2074
2055
nested_shape. width ,
2075
2056
) ;
2076
- tactic = if args_tactic == DefinitiveListTactic :: Horizontal {
2077
- DefinitiveListTactic :: WriteCall
2078
- } else {
2079
- default_tactic ( )
2080
- } ;
2057
+
2058
+ // Every argument is simple and fits on a single line.
2059
+ if args_tactic == DefinitiveListTactic :: Horizontal {
2060
+ tactic = if args_offset == 1 {
2061
+ DefinitiveListTactic :: FormatCall
2062
+ } else {
2063
+ DefinitiveListTactic :: WriteCall
2064
+ } ;
2065
+ }
2081
2066
}
2082
2067
}
2083
2068
}
@@ -2111,6 +2096,29 @@ fn is_every_args_simple<T: ToExpr>(lists: &[&T]) -> bool {
2111
2096
. all ( |arg| arg. to_expr ( ) . map_or ( false , is_simple_arg) )
2112
2097
}
2113
2098
2099
+ /// In case special-case style is required, returns an offset from which we start horizontal layout.
2100
+ fn maybe_get_args_offset < T : ToExpr > ( callee_str : & str , args : & [ & T ] ) -> Option < usize > {
2101
+ if FORMAT_LIKE_WHITELIST
2102
+ . iter ( )
2103
+ . find ( |s| * * s == callee_str)
2104
+ . is_some ( )
2105
+ && args. len ( ) >= 1
2106
+ && is_every_args_simple ( args)
2107
+ {
2108
+ Some ( 1 )
2109
+ } else if WRITE_LIKE_WHITELIST
2110
+ . iter ( )
2111
+ . find ( |s| * * s == callee_str)
2112
+ . is_some ( )
2113
+ && args. len ( ) >= 2
2114
+ && is_every_args_simple ( args)
2115
+ {
2116
+ Some ( 2 )
2117
+ } else {
2118
+ None
2119
+ }
2120
+ }
2121
+
2114
2122
/// Returns a shape for the last argument which is going to be overflowed.
2115
2123
fn last_arg_shape < T > (
2116
2124
lists : & [ & T ] ,
0 commit comments