mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-25 06:03:16 +00:00
Merge pull request #2332 from topecongiro/impl-and-trait
Fix up formatting bugs in impl and trait
This commit is contained in:
commit
e343aa24b3
10
src/items.rs
10
src/items.rs
@ -33,8 +33,8 @@ use types::join_bounds;
|
|||||||
use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_constness,
|
use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_constness,
|
||||||
format_defaultness, format_mutability, format_unsafety, format_visibility,
|
format_defaultness, format_mutability, format_unsafety, format_visibility,
|
||||||
is_attributes_extendable, last_line_contains_single_line_comment,
|
is_attributes_extendable, last_line_contains_single_line_comment,
|
||||||
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
|
last_line_extendable, last_line_used_width, last_line_width, mk_sp,
|
||||||
stmt_expr, trimmed_last_line_width};
|
semicolon_for_expr, starts_with_newline, stmt_expr, trimmed_last_line_width};
|
||||||
use vertical::rewrite_with_alignment;
|
use vertical::rewrite_with_alignment;
|
||||||
use visitor::FmtVisitor;
|
use visitor::FmtVisitor;
|
||||||
|
|
||||||
@ -639,8 +639,10 @@ pub fn format_impl(
|
|||||||
}
|
}
|
||||||
result.push_str(&where_clause_str);
|
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() {
|
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::AlwaysNextLine => result.push_str(&sep),
|
||||||
BraceStyle::PreferSameLine => result.push(' '),
|
BraceStyle::PreferSameLine => result.push(' '),
|
||||||
BraceStyle::SameLineWhere => {
|
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 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 =
|
let generics_str =
|
||||||
rewrite_generics(context, generics, shape, mk_sp(item.span.lo(), body_lo))?;
|
rewrite_generics(context, generics, shape, mk_sp(item.span.lo(), body_lo))?;
|
||||||
result.push_str(&generics_str);
|
result.push_str(&generics_str);
|
||||||
|
@ -178,7 +178,7 @@ pub fn last_line_extendable(s: &str) -> bool {
|
|||||||
}
|
}
|
||||||
for c in s.chars().rev() {
|
for c in s.chars().rev() {
|
||||||
match c {
|
match c {
|
||||||
')' | ']' | '}' | '?' => continue,
|
')' | ']' | '}' | '?' | '>' => continue,
|
||||||
'\n' => break,
|
'\n' => break,
|
||||||
_ if c.is_whitespace() => continue,
|
_ if c.is_whitespace() => continue,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
|
@ -72,6 +72,11 @@ trait Foo {
|
|||||||
type IteRev = <MergingUntypedTimeSeries<SliceSeries<SliceWindow>> as UntypedTimeSeries>::IterRev;
|
type IteRev = <MergingUntypedTimeSeries<SliceSeries<SliceWindow>> as UntypedTimeSeries>::IterRev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #2331
|
||||||
|
trait MyTrait<AAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBB, CCCCCCCCCCCCCCCCCCCC, DDDDDDDDDDDDDDDDDDDD> {
|
||||||
|
fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
// Trait aliases
|
// Trait aliases
|
||||||
trait FooBar =
|
trait FooBar =
|
||||||
Foo
|
Foo
|
||||||
|
@ -29,11 +29,13 @@ where
|
|||||||
|
|
||||||
// #1369
|
// #1369
|
||||||
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
||||||
for Bar {
|
for Bar
|
||||||
|
{
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
||||||
for Bar {
|
for Bar
|
||||||
|
{
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
impl<
|
impl<
|
||||||
@ -41,7 +43,8 @@ impl<
|
|||||||
ExcessivelyLongGenericName,
|
ExcessivelyLongGenericName,
|
||||||
AnotherExcessivelyLongGenericName,
|
AnotherExcessivelyLongGenericName,
|
||||||
> Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
> Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
||||||
for Bar {
|
for Bar
|
||||||
|
{
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
||||||
|
@ -27,11 +27,13 @@ where
|
|||||||
|
|
||||||
// #1369
|
// #1369
|
||||||
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
||||||
for Bar {
|
for Bar
|
||||||
|
{
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
impl Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
||||||
for Bar {
|
for Bar
|
||||||
|
{
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
impl<
|
impl<
|
||||||
@ -39,7 +41,8 @@ impl<
|
|||||||
ExcessivelyLongGenericName,
|
ExcessivelyLongGenericName,
|
||||||
AnotherExcessivelyLongGenericName,
|
AnotherExcessivelyLongGenericName,
|
||||||
> Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
> Foo<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName>
|
||||||
for Bar {
|
for Bar
|
||||||
|
{
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
impl<ExcessivelyLongGenericName, ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName> Foo
|
||||||
|
@ -141,11 +141,13 @@ mod m {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<BorrowType, K, V, NodeType, HandleType>
|
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
|
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 {
|
mod x {
|
||||||
@ -160,7 +162,8 @@ mod x {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNodeFoo>
|
impl<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNodeFoo>
|
||||||
Issue1249<ConcreteThreadSafeLayoutNode> {
|
Issue1249<ConcreteThreadSafeLayoutNode>
|
||||||
|
{
|
||||||
// Creates a new flow constructor.
|
// Creates a new flow constructor.
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,16 @@ trait Foo {
|
|||||||
<MergingUntypedTimeSeries<SliceSeries<SliceWindow>> as UntypedTimeSeries>::IterRev;
|
<MergingUntypedTimeSeries<SliceSeries<SliceWindow>> as UntypedTimeSeries>::IterRev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #2331
|
||||||
|
trait MyTrait<
|
||||||
|
AAAAAAAAAAAAAAAAAAAA,
|
||||||
|
BBBBBBBBBBBBBBBBBBBB,
|
||||||
|
CCCCCCCCCCCCCCCCCCCC,
|
||||||
|
DDDDDDDDDDDDDDDDDDDD,
|
||||||
|
> {
|
||||||
|
fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
// Trait aliases
|
// Trait aliases
|
||||||
trait FooBar = Foo + Bar;
|
trait FooBar = Foo + Bar;
|
||||||
trait FooBar<A, B, C> = Foo + Bar;
|
trait FooBar<A, B, C> = Foo + Bar;
|
||||||
|
Loading…
Reference in New Issue
Block a user