Fix brace indentation for impl items (#927)

This commit is contained in:
Marcus Klaas de Vries 2016-04-14 20:42:38 +02:00
parent 3cc24c6a1a
commit 320df84e96
3 changed files with 27 additions and 3 deletions

View file

@ -499,7 +499,8 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
if try_opt!(is_impl_single_line(context, &items, &result, &where_clause_str, &item)) {
result.push_str(&where_clause_str);
if where_clause_str.contains('\n') {
result.push_str("\n{\n}");
let white_space = offset.to_string(context.config);
result.push_str(&format!("\n{}{{\n{}}}", &white_space, &white_space));
} else {
result.push_str(" {}");
}
@ -519,9 +520,10 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
BraceStyle::PreferSameLine => result.push(' '),
BraceStyle::SameLineWhere => {
if !where_clause_str.is_empty() {
result.push('\n')
result.push('\n');
result.push_str(&offset.to_string(context.config));
} else {
result.push(' ')
result.push(' ');
}
}
}

View file

@ -87,3 +87,13 @@ pub impl<T> Foo for Bar<T> where T: Foo
}
pub impl<T, Z> Foo for Bar<T, Z> where T: Foo, Z: Baz {}
mod m {
impl<T> PartialEq for S<T> where T: PartialEq {
fn eq(&self, other: &Self) {
true
}
}
impl<T> PartialEq for S<T> where T: PartialEq { }
}

View file

@ -112,3 +112,15 @@ pub impl<T, Z> Foo for Bar<T, Z>
Z: Baz
{
}
mod m {
impl<T> PartialEq for S<T>
where T: PartialEq
{
fn eq(&self, other: &Self) {
true
}
}
impl<T> PartialEq for S<T> where T: PartialEq {}
}