diff --git a/src/items.rs b/src/items.rs index 1de56220cf4..82f7dcfe711 100644 --- a/src/items.rs +++ b/src/items.rs @@ -440,6 +440,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - ref self_ty, ref items) = item.node { let mut result = String::new(); + result.push_str(&*format_visibility(&item.vis)); result.push_str(format_unsafety(unsafety)); result.push_str("impl"); @@ -470,7 +471,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - result.push_str(" for "); } - let budget = try_opt!(context.config.max_width.checked_sub(result.len())); + let budget = try_opt!(context.config.max_width.checked_sub(result.len() + 1)); let indent = offset + result.len(); result.push_str(&*try_opt!(self_ty.rewrite(context, budget, indent))); @@ -1359,8 +1360,9 @@ fn rewrite_fn_base(context: &RewriteContext, _ => { // If we've already gone multi-line, or the return type would push // over the max width, then put the return type on a new line. - result.contains("\n") || multi_line_ret_str || - result.len() + indent.width() + ret_str_len > context.config.max_width + let overlong_ret = result.len() + indent.width() + ret_str_len > + context.config.max_width - 1; + result.contains("\n") || multi_line_ret_str || overlong_ret } }; let ret_indent = if ret_should_indent { @@ -1388,10 +1390,8 @@ fn rewrite_fn_base(context: &RewriteContext, if multi_line_ret_str { // Now that we know the proper indent and width, we need to // re-layout the return type. - let budget = try_opt!(context.config.max_width.checked_sub(ret_indent.width())); - let ret_str = try_opt!(fd.output - .rewrite(context, budget, ret_indent)); + let ret_str = try_opt!(fd.output.rewrite(context, budget, ret_indent)); result.push_str(&ret_str); } else { result.push_str(&ret_str); diff --git a/tests/source/issue-1048.rs b/tests/source/issue-1048.rs new file mode 100644 index 00000000000..40df8b81914 --- /dev/null +++ b/tests/source/issue-1048.rs @@ -0,0 +1,3 @@ +// Test issue-1048 +impl Handle, HandleType> { +} diff --git a/tests/source/issue-1049.rs b/tests/source/issue-1049.rs new file mode 100644 index 00000000000..2d76cc489e2 --- /dev/null +++ b/tests/source/issue-1049.rs @@ -0,0 +1,6 @@ +// Test issue-1049 +pub unsafe fn reborrow_mut(&mut X: Abcde) -> Handle, HandleType> { +} + +pub fn merge(mut X: Abcdef) -> Handle, K, V, marker::Internal>, marker::Edge> { +} diff --git a/tests/target/issue-1048.rs b/tests/target/issue-1048.rs new file mode 100644 index 00000000000..af1be8aeab3 --- /dev/null +++ b/tests/target/issue-1048.rs @@ -0,0 +1,4 @@ +// Test issue-1048 +impl Handle, + HandleType> { +} diff --git a/tests/target/issue-1049.rs b/tests/target/issue-1049.rs new file mode 100644 index 00000000000..0529e861f69 --- /dev/null +++ b/tests/target/issue-1049.rs @@ -0,0 +1,8 @@ +// Test issue-1049 +pub unsafe fn reborrow_mut(&mut X: Abcde) + -> Handle, HandleType> { +} + +pub fn merge(mut X: Abcdef) + -> Handle, K, V, marker::Internal>, marker::Edge> { +}