@@ -18,7 +18,6 @@ use syntax::{ast, ptr};
18
18
use closures;
19
19
use expr:: {
20
20
can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr,
21
- maybe_get_args_offset,
22
21
} ;
23
22
use lists:: { definitive_tactic, itemize_list, write_list, ListFormatting , ListItem , Separator } ;
24
23
use macros:: MacroArg ;
@@ -32,6 +31,42 @@ use utils::{count_newlines, extra_offset, first_line_width, last_line_width, mk_
32
31
33
32
use std:: cmp:: min;
34
33
34
+ const SHORT_ITEM_THRESHOLD : usize = 10 ;
35
+
36
+ /// A list of `format!`-like macros, that take a long format string and a list of arguments to
37
+ /// format.
38
+ ///
39
+ /// Organized as a list of `(&str, usize)` tuples, giving the name of the macro and the number of
40
+ /// arguments before the format string (none for `format!("format", ...)`, one for `assert!(result,
41
+ /// "format", ...)`, two for `assert_eq!(left, right, "format", ...)`).
42
+ const SPECIAL_MACRO_WHITELIST : & [ ( & str , usize ) ] = & [
43
+ // format! like macros
44
+ // From the Rust Standard Library.
45
+ ( "eprint!" , 0 ) ,
46
+ ( "eprintln!" , 0 ) ,
47
+ ( "format!" , 0 ) ,
48
+ ( "format_args!" , 0 ) ,
49
+ ( "print!" , 0 ) ,
50
+ ( "println!" , 0 ) ,
51
+ ( "panic!" , 0 ) ,
52
+ ( "unreachable!" , 0 ) ,
53
+ // From the `log` crate.
54
+ ( "debug!" , 0 ) ,
55
+ ( "error!" , 0 ) ,
56
+ ( "info!" , 0 ) ,
57
+ ( "warn!" , 0 ) ,
58
+ // write! like macros
59
+ ( "assert!" , 1 ) ,
60
+ ( "debug_assert!" , 1 ) ,
61
+ ( "write!" , 1 ) ,
62
+ ( "writeln!" , 1 ) ,
63
+ // assert_eq! like macros
64
+ ( "assert_eq!" , 2 ) ,
65
+ ( "assert_ne!" , 2 ) ,
66
+ ( "debug_assert_eq!" , 2 ) ,
67
+ ( "debug_assert_ne!" , 2 ) ,
68
+ ] ;
69
+
35
70
pub enum OverflowableItem < ' a > {
36
71
Expr ( & ' a ast:: Expr ) ,
37
72
GenericParam ( & ' a ast:: GenericParam ) ,
@@ -178,8 +213,6 @@ where
178
213
iter. map ( |x| IntoOverflowableItem :: into_overflowable_item ( x) )
179
214
}
180
215
181
- const SHORT_ITEM_THRESHOLD : usize = 10 ;
182
-
183
216
pub fn rewrite_with_parens < ' a , T : ' a + IntoOverflowableItem < ' a > > (
184
217
context : & ' a RewriteContext ,
185
218
ident : & ' a str ,
@@ -661,3 +694,21 @@ fn no_long_items(list: &[ListItem]) -> bool {
661
694
list. iter ( )
662
695
. all ( |item| item. inner_as_ref ( ) . len ( ) <= SHORT_ITEM_THRESHOLD )
663
696
}
697
+
698
+ /// In case special-case style is required, returns an offset from which we start horizontal layout.
699
+ pub fn maybe_get_args_offset ( callee_str : & str , args : & [ OverflowableItem ] ) -> Option < ( bool , usize ) > {
700
+ if let Some ( & ( _, num_args_before) ) = args
701
+ . get ( 0 ) ?
702
+ . whitelist ( )
703
+ . iter ( )
704
+ . find ( |& & ( s, _) | s == callee_str)
705
+ {
706
+ let all_simple = args. len ( ) > num_args_before
707
+ && is_every_expr_simple ( & args[ 0 ..num_args_before] )
708
+ && is_every_expr_simple ( & args[ num_args_before + 1 ..] ) ;
709
+
710
+ Some ( ( all_simple, num_args_before) )
711
+ } else {
712
+ None
713
+ }
714
+ }
0 commit comments