Fix overlong impl (#1091)

* Fix issue-1048

* Take possible where-clause into account

* Move test to existing test set

* Fix wrong variable name
This commit is contained in:
dawirstejeck 2016-07-26 07:34:11 +02:00 committed by Nick Cameron
parent 78b52ec3e1
commit e76cb6a907
3 changed files with 20 additions and 1 deletions

View File

@ -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,18 @@ 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 mut used_space = result.len();
if generics.where_clause.predicates.is_empty() {
// If there is no where clause adapt budget for type formatting to take space and curly
// brace into account.
match context.config.item_brace_style {
BraceStyle::AlwaysNextLine => {}
BraceStyle::PreferSameLine => used_space += 2,
BraceStyle::SameLineWhere => used_space += 2,
}
}
let budget = try_opt!(context.config.max_width.checked_sub(used_space));
let indent = offset + result.len();
result.push_str(&*try_opt!(self_ty.rewrite(context, budget, indent)));

View File

@ -97,3 +97,6 @@ mod m {
impl<T> PartialEq for S<T> where T: PartialEq { }
}
impl<BorrowType, K, V, NodeType, HandleType> Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType> {
}

View File

@ -124,3 +124,7 @@ mod m {
impl<T> PartialEq for S<T> where T: PartialEq {}
}
impl<BorrowType, K, V, NodeType, HandleType> Handle<NodeRef<BorrowType, K, V, NodeType>,
HandleType> {
}