Skip to content

Fix overlong impl #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tests/source/issue-1048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Test issue-1048
impl<BorrowType, K, V, NodeType, HandleType> Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType> {
}
6 changes: 6 additions & 0 deletions tests/source/issue-1049.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Test issue-1049
pub unsafe fn reborrow_mut(&mut X: Abcde) -> Handle<NodeRef<marker::Mut, K, V, NodeType>, HandleType> {
}

pub fn merge(mut X: Abcdef) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge> {
}
4 changes: 4 additions & 0 deletions tests/target/issue-1048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Test issue-1048
impl<BorrowType, K, V, NodeType, HandleType> Handle<NodeRef<BorrowType, K, V, NodeType>,
HandleType> {
}
8 changes: 8 additions & 0 deletions tests/target/issue-1049.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Test issue-1049
pub unsafe fn reborrow_mut(&mut X: Abcde)
-> Handle<NodeRef<marker::Mut, K, V, NodeType>, HandleType> {
}

pub fn merge(mut X: Abcdef)
-> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge> {
}