Merge pull request #2332 from topecongiro/impl-and-trait

Fix up formatting bugs in impl and trait
This commit is contained in:
Nick Cameron 2018-01-04 16:51:56 +13:00 committed by GitHub
commit e343aa24b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 14 deletions

View File

@ -33,8 +33,8 @@ use types::join_bounds;
use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_constness,
format_defaultness, format_mutability, format_unsafety, format_visibility,
is_attributes_extendable, last_line_contains_single_line_comment,
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
stmt_expr, trimmed_last_line_width};
last_line_extendable, last_line_used_width, last_line_width, mk_sp,
semicolon_for_expr, starts_with_newline, stmt_expr, trimmed_last_line_width};
use vertical::rewrite_with_alignment;
use visitor::FmtVisitor;
@ -639,8 +639,10 @@ pub fn format_impl(
}
result.push_str(&where_clause_str);
let need_newline = !last_line_extendable(&result)
&& (last_line_contains_single_line_comment(&result) || result.contains('\n'));
match context.config.brace_style() {
_ if last_line_contains_single_line_comment(&result) => result.push_str(&sep),
_ if need_newline => result.push_str(&sep),
BraceStyle::AlwaysNextLine => result.push_str(&sep),
BraceStyle::PreferSameLine => result.push(' '),
BraceStyle::SameLineWhere => {
@ -938,7 +940,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
let body_lo = context.codemap.span_after(item.span, "{");
let shape = Shape::indented(offset, context.config);
let shape = Shape::indented(offset, context.config).offset_left(result.len())?;
let generics_str =
rewrite_generics(context, generics, shape, mk_sp(item.span.lo(), body_lo))?;
result.push_str(&generics_str);

View File

@ -178,7 +178,7 @@ pub fn last_line_extendable(s: &str) -> bool {
}
for c in s.chars().rev() {
match c {
')' | ']' | '}' | '?' => continue,
')' | ']' | '}' | '?' | '>' => continue,
'\n' => break,
_ if c.is_whitespace() => continue,
_ => return false,

View File

@ -72,6 +72,11 @@ trait Foo {
type IteRev = <MergingUntypedTimeSeries<SliceSeries<SliceWindow>> as UntypedTimeSeries>::IterRev;
}
// #2331
trait MyTrait<AAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBB, CCCCCCCCCCCCCCCCCCCC, DDDDDDDDDDDDDDDDDDDD> {
fn foo() {}
}
// Trait aliases
trait FooBar =
Foo

View File

@ -29,11 +29,13 @@ where
// #1369
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
for Bar {
for Bar
{
fn foo() {}
}
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
for Bar {
for Bar
{
fn foo() {}
}
impl<
@ -41,7 +43,8 @@ impl<
ExcessivelyLongGenericName,
AnotherExcessivelyLongGenericName,
> Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
for Bar {
for Bar
{
fn foo() {}
}
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo

View File

@ -27,11 +27,13 @@ where
// #1369
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
for Bar {
for Bar
{
fn foo() {}
}
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
for Bar {
for Bar
{
fn foo() {}
}
impl<
@ -39,7 +41,8 @@ impl<
ExcessivelyLongGenericName,
AnotherExcessivelyLongGenericName,
> Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
for Bar {
for Bar
{
fn foo() {}
}
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo

View File

@ -141,11 +141,13 @@ mod m {
}
impl<BorrowType, K, V, NodeType, HandleType>
Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType> {
Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType>
{
}
impl<BorrowType, K, V, NodeType, HandleType> PartialEq
for Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType> {
for Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType>
{
}
mod x {
@ -160,7 +162,8 @@ mod x {
}
impl<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNodeFoo>
Issue1249<ConcreteThreadSafeLayoutNode> {
Issue1249<ConcreteThreadSafeLayoutNode>
{
// Creates a new flow constructor.
fn foo() {}
}

View File

@ -100,6 +100,16 @@ trait Foo {
<MergingUntypedTimeSeries<SliceSeries<SliceWindow>> as UntypedTimeSeries>::IterRev;
}
// #2331
trait MyTrait<
AAAAAAAAAAAAAAAAAAAA,
BBBBBBBBBBBBBBBBBBBB,
CCCCCCCCCCCCCCCCCCCC,
DDDDDDDDDDDDDDDDDDDD,
> {
fn foo() {}
}
// Trait aliases
trait FooBar = Foo + Bar;
trait FooBar<A, B, C> = Foo + Bar;