Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 052ba6c

Browse files
committed
Move maybe_get_args_offset to overflow.rs
1 parent 6338782 commit 052ba6c

File tree

2 files changed

+54
-51
lines changed

2 files changed

+54
-51
lines changed

src/expr.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,54 +1259,6 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
12591259
)
12601260
}
12611261

1262-
/// In case special-case style is required, returns an offset from which we start horizontal layout.
1263-
pub fn maybe_get_args_offset(callee_str: &str, args: &[OverflowableItem]) -> Option<(bool, usize)> {
1264-
if let Some(&(_, num_args_before)) = SPECIAL_MACRO_WHITELIST
1265-
.iter()
1266-
.find(|&&(s, _)| s == callee_str)
1267-
{
1268-
let all_simple = args.len() > num_args_before && is_every_expr_simple(args);
1269-
1270-
Some((all_simple, num_args_before))
1271-
} else {
1272-
None
1273-
}
1274-
}
1275-
1276-
/// A list of `format!`-like macros, that take a long format string and a list of arguments to
1277-
/// format.
1278-
///
1279-
/// Organized as a list of `(&str, usize)` tuples, giving the name of the macro and the number of
1280-
/// arguments before the format string (none for `format!("format", ...)`, one for `assert!(result,
1281-
/// "format", ...)`, two for `assert_eq!(left, right, "format", ...)`).
1282-
const SPECIAL_MACRO_WHITELIST: &[(&str, usize)] = &[
1283-
// format! like macros
1284-
// From the Rust Standard Library.
1285-
("eprint!", 0),
1286-
("eprintln!", 0),
1287-
("format!", 0),
1288-
("format_args!", 0),
1289-
("print!", 0),
1290-
("println!", 0),
1291-
("panic!", 0),
1292-
("unreachable!", 0),
1293-
// From the `log` crate.
1294-
("debug!", 0),
1295-
("error!", 0),
1296-
("info!", 0),
1297-
("warn!", 0),
1298-
// write! like macros
1299-
("assert!", 1),
1300-
("debug_assert!", 1),
1301-
("write!", 1),
1302-
("writeln!", 1),
1303-
// assert_eq! like macros
1304-
("assert_eq!", 2),
1305-
("assert_ne!", 2),
1306-
("debug_assert_eq!", 2),
1307-
("debug_assert_ne!", 2),
1308-
];
1309-
13101262
fn choose_separator_tactic(context: &RewriteContext, span: Span) -> Option<SeparatorTactic> {
13111263
if context.inside_macro() {
13121264
if span_ends_with_comma(context, span) {

src/overflow.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use syntax::{ast, ptr};
1818
use closures;
1919
use expr::{
2020
can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr,
21-
maybe_get_args_offset,
2221
};
2322
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
2423
use macros::MacroArg;
@@ -32,6 +31,42 @@ use utils::{count_newlines, extra_offset, first_line_width, last_line_width, mk_
3231

3332
use std::cmp::min;
3433

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+
3570
pub enum OverflowableItem<'a> {
3671
Expr(&'a ast::Expr),
3772
GenericParam(&'a ast::GenericParam),
@@ -178,8 +213,6 @@ where
178213
iter.map(|x| IntoOverflowableItem::into_overflowable_item(x))
179214
}
180215

181-
const SHORT_ITEM_THRESHOLD: usize = 10;
182-
183216
pub fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>(
184217
context: &'a RewriteContext,
185218
ident: &'a str,
@@ -661,3 +694,21 @@ fn no_long_items(list: &[ListItem]) -> bool {
661694
list.iter()
662695
.all(|item| item.inner_as_ref().len() <= SHORT_ITEM_THRESHOLD)
663696
}
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

Comments
 (0)