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:
parent
78b52ec3e1
commit
e76cb6a907
14
src/items.rs
14
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,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)));
|
||||
|
||||
|
@ -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> {
|
||||
}
|
||||
|
@ -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> {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user