diff --git a/src/items.rs b/src/items.rs index 5c5e9923b32..46446eda779 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1301,7 +1301,7 @@ fn rewrite_fn_base(context: &RewriteContext, // Args. let (mut one_line_budget, mut multi_line_budget, mut arg_indent) = - compute_budgets_for_args(context, &result, indent, ret_str_len, newline_brace); + try_opt!(compute_budgets_for_args(context, &result, indent, ret_str_len, newline_brace)); if context.config.fn_args_layout == FnArgLayoutStyle::Block || context.config.fn_args_layout == FnArgLayoutStyle::BlockAlways { @@ -1617,7 +1617,7 @@ fn compute_budgets_for_args(context: &RewriteContext, indent: Indent, ret_str_len: usize, newline_brace: bool) - -> (usize, usize, Indent) { + -> Option<((usize, usize, Indent))> { // Try keeping everything on the same line. if !result.contains("\n") { // 3 = `() `, space is before ret_string. @@ -1628,23 +1628,23 @@ fn compute_budgets_for_args(context: &RewriteContext, let one_line_budget = context.config.max_width.checked_sub(used_space).unwrap_or(0); if one_line_budget > 0 { - let multi_line_budget = context.config.max_width - - (indent.width() + result.len() + "()".len()); + // 4 = "() {".len() + let multi_line_budget = + try_opt!(context.config.max_width.checked_sub(indent.width() + result.len() + 4)); - return (one_line_budget, multi_line_budget, indent + result.len() + 1); + return Some((one_line_budget, multi_line_budget, indent + result.len() + 1)); } } // Didn't work. we must force vertical layout and put args on a newline. let new_indent = indent.block_indent(context.config); - let used_space = new_indent.width() + 2; // account for `(` and `)` + let used_space = new_indent.width() + 4; // Account for `(` and `)` and possibly ` {`. let max_space = context.config.max_width; if used_space <= max_space { - (0, max_space - used_space, new_indent) + Some((0, max_space - used_space, new_indent)) } else { // Whoops! bankrupt. - // FIXME: take evasive action, perhaps kill the indent or something. - panic!("in compute_budgets_for_args"); + None } } diff --git a/tests/target/fn-custom.rs b/tests/target/fn-custom.rs index c991142fa6c..ad36de7a997 100644 --- a/tests/target/fn-custom.rs +++ b/tests/target/fn-custom.rs @@ -2,8 +2,8 @@ // Test some of the ways function signatures can be customised. // Test compressed layout of args. -fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, - e: Eeeeeeeeeeeeeeeeeee) { +fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, + d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) { foo(); } diff --git a/tests/target/fn.rs b/tests/target/fn.rs index 02600f43f2a..9ba150d6115 100644 --- a/tests/target/fn.rs +++ b/tests/target/fn.rs @@ -88,3 +88,18 @@ fn ______________________baz(a: i32) arg3: i32) -> ()> { } + +pub fn check_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + path: &hir::Path, + id: ast::NodeId, + cb: &mut FnMut(DefId, Span, &Option<&Stability>, &Option)) { +} + +pub fn check_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + path: &hir::Path, + id: ast::NodeId, + cb: &mut FnMut(DefId, + Span, + &Option<&Stability>, + &Option)) { +}