Skip to content

Commit d633e83

Browse files
committed
Merge pull request #1009 from rust-lang-nursery/fn-args-1
Fix off by 2 error in function sigs
2 parents d6bcfce + 882ef8c commit d633e83

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/items.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ fn rewrite_fn_base(context: &RewriteContext,
13011301

13021302
// Args.
13031303
let (mut one_line_budget, mut multi_line_budget, mut arg_indent) =
1304-
compute_budgets_for_args(context, &result, indent, ret_str_len, newline_brace);
1304+
try_opt!(compute_budgets_for_args(context, &result, indent, ret_str_len, newline_brace));
13051305

13061306
if context.config.fn_args_layout == FnArgLayoutStyle::Block ||
13071307
context.config.fn_args_layout == FnArgLayoutStyle::BlockAlways {
@@ -1617,7 +1617,7 @@ fn compute_budgets_for_args(context: &RewriteContext,
16171617
indent: Indent,
16181618
ret_str_len: usize,
16191619
newline_brace: bool)
1620-
-> (usize, usize, Indent) {
1620+
-> Option<((usize, usize, Indent))> {
16211621
// Try keeping everything on the same line.
16221622
if !result.contains("\n") {
16231623
// 3 = `() `, space is before ret_string.
@@ -1628,23 +1628,23 @@ fn compute_budgets_for_args(context: &RewriteContext,
16281628
let one_line_budget = context.config.max_width.checked_sub(used_space).unwrap_or(0);
16291629

16301630
if one_line_budget > 0 {
1631-
let multi_line_budget = context.config.max_width -
1632-
(indent.width() + result.len() + "()".len());
1631+
// 4 = "() {".len()
1632+
let multi_line_budget =
1633+
try_opt!(context.config.max_width.checked_sub(indent.width() + result.len() + 4));
16331634

1634-
return (one_line_budget, multi_line_budget, indent + result.len() + 1);
1635+
return Some((one_line_budget, multi_line_budget, indent + result.len() + 1));
16351636
}
16361637
}
16371638

16381639
// Didn't work. we must force vertical layout and put args on a newline.
16391640
let new_indent = indent.block_indent(context.config);
1640-
let used_space = new_indent.width() + 2; // account for `(` and `)`
1641+
let used_space = new_indent.width() + 4; // Account for `(` and `)` and possibly ` {`.
16411642
let max_space = context.config.max_width;
16421643
if used_space <= max_space {
1643-
(0, max_space - used_space, new_indent)
1644+
Some((0, max_space - used_space, new_indent))
16441645
} else {
16451646
// Whoops! bankrupt.
1646-
// FIXME: take evasive action, perhaps kill the indent or something.
1647-
panic!("in compute_budgets_for_args");
1647+
None
16481648
}
16491649
}
16501650

tests/target/fn-custom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Test some of the ways function signatures can be customised.
33

44
// Test compressed layout of args.
5-
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd,
6-
e: Eeeeeeeeeeeeeeeeeee) {
5+
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc,
6+
d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
77
foo();
88
}
99

tests/target/fn.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@ fn ______________________baz(a: i32)
8888
arg3: i32)
8989
-> ()> {
9090
}
91+
92+
pub fn check_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
93+
path: &hir::Path,
94+
id: ast::NodeId,
95+
cb: &mut FnMut(DefId, Span, &Option<&Stability>, &Option<Depecation>)) {
96+
}
97+
98+
pub fn check_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
99+
path: &hir::Path,
100+
id: ast::NodeId,
101+
cb: &mut FnMut(DefId,
102+
Span,
103+
&Option<&Stability>,
104+
&Option<Deprecation>)) {
105+
}

0 commit comments

Comments
 (0)