From 6a7f866cfececbdb1aeea9d654e42aecfc8e4bca Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sat, 24 Jun 2017 19:49:01 +0900 Subject: [PATCH] Format source codes --- src/expr.rs | 3 +- src/file_lines.rs | 4 +- src/items.rs | 5 ++ ...configs-struct_field_align_threshold-20.rs | 46 +++++++++++++------ tests/target/macros.rs | 2 +- tests/target/multiple.rs | 2 +- tests/target/paths.rs | 5 +- tests/target/struct_tuple_visual.rs | 4 +- tests/target/structs.rs | 23 ++++++++-- tests/target/trailing_commas.rs | 5 +- 10 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 4bea5f4c0e19..1696577f023a 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -3035,8 +3035,7 @@ fn to_expr(&self) -> Option<&ast::Expr> { None } - #[allow(unused_variables)] - fn can_be_overflowed(&self, context: &RewriteContext, len: usize) -> bool { + fn can_be_overflowed(&self, _: &RewriteContext, _: usize) -> bool { false } } diff --git a/src/file_lines.rs b/src/file_lines.rs index dad7d0b061af..7df4dbb73994 100644 --- a/src/file_lines.rs +++ b/src/file_lines.rs @@ -167,7 +167,9 @@ pub fn intersects_range(&self, file_name: &str, lo: usize, hi: usize) -> bool { } /// FileLines files iterator. -pub struct Files<'a>(Option<::std::collections::hash_map::Keys<'a, String, Vec>>); +pub struct Files<'a>( + Option<::std::collections::hash_map::Keys<'a, String, Vec>>, +); impl<'a> iter::Iterator for Files<'a> { type Item = &'a String; diff --git a/src/items.rs b/src/items.rs index aa19e4238a50..a70d72e7b266 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1419,6 +1419,11 @@ fn rewrite_struct_field_type( .map(|ty| format!("{}{}", spacing, ty)) } +impl Rewrite for ast::StructField { + fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + rewrite_struct_field(context, self, shape, 0) + } +} pub fn rewrite_struct_field( context: &RewriteContext, diff --git a/tests/target/configs-struct_field_align_threshold-20.rs b/tests/target/configs-struct_field_align_threshold-20.rs index db3458bda153..509bcbf6d64e 100644 --- a/tests/target/configs-struct_field_align_threshold-20.rs +++ b/tests/target/configs-struct_field_align_threshold-20.rs @@ -73,14 +73,19 @@ pub struct Writebatch { struct NewType(Type, OtherType); -struct NewInt(pub i32, SomeType /* inline comment */, T /* sup */); +struct NewInt( + pub i32, + SomeType, // inline comment + T, // sup +); -struct Qux<'a, - N: Clone + 'a, - E: Clone + 'a, - G: Labeller<'a, N, E> + GraphWalk<'a, N, E>, - W: Write + Copy> -( +struct Qux< + 'a, + N: Clone + 'a, + E: Clone + 'a, + G: Labeller<'a, N, E> + GraphWalk<'a, N, E>, + W: Write + Copy, +>( AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, #[AnAttr] @@ -94,7 +99,7 @@ struct Tuple( // Comment 1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment 2 - BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, ); // With a where clause and generics. @@ -139,7 +144,10 @@ struct Baz { } // Will this be a one-liner? -struct Tuple(A /* Comment */, B); +struct Tuple( + A, // Comment + B, +); pub struct State time::Timespec> { now: F, @@ -186,19 +194,27 @@ struct Foo( TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, - UUUUUUUUUUUUUUUUUUU + UUUUUUUUUUUUUUUUUUU, ); -struct Foo(TTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT) +struct Foo( + TTTTTTTTTTTTTTTTTT, + UUUUUUUUUUUUUUUUUUUUUUUU, + TTTTTTTTTTTTTTTTTTT, +) where T: PartialEq; -struct Foo(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTTTT) +struct Foo( + TTTTTTTTTTTTTTTTT, + UUUUUUUUUUUUUUUUUUUUUUUU, + TTTTTTTTTTTTTTTTTTTTT, +) where T: PartialEq; struct Foo( TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, - UUUUUUUUUUUUUUUUUUU + UUUUUUUUUUUUUUUUUUU, ) where T: PartialEq; @@ -208,7 +224,7 @@ struct Foo( // Baz TTTTTTTTTTTTTTTTTTT, // Qux (FIXME #572 - doc comment) - UUUUUUUUUUUUUUUUUUU + UUUUUUUUUUUUUUUUUUU, ); mod m { @@ -223,7 +239,7 @@ struct X struct Foo( TTTTTTTTTTTTTTTTTTT, /// Qux - UUUUUUUUUUUUUUUUUUU + UUUUUUUUUUUUUUUUUUU, ); struct Issue677 { diff --git a/tests/target/macros.rs b/tests/target/macros.rs index eb95fe4758c2..1f482075df47 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -29,7 +29,7 @@ fn main() { kaas!( // comments a, // post macro - b /* another */ + b // another ); trailingcomma!(a, b, c,); diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index 9e5785dc2419..d8dea8896f2b 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -40,7 +40,7 @@ fn foo() -> Box fn baz< 'a: 'b, // comment on 'a - T: SomsssssssssssssssssssssssssssssssssssssssssssssssssssssseType, /* comment on T */ + T: SomsssssssssssssssssssssssssssssssssssssssssssssssssssssseType, // comment on T >( a: A, b: B, // comment on b diff --git a/tests/target/paths.rs b/tests/target/paths.rs index 9b48dd9a470b..0d2ba797eb79 100644 --- a/tests/target/paths.rs +++ b/tests/target/paths.rs @@ -14,7 +14,10 @@ fn main() { supports_clipboard, ); - Quux::::some_func(); + Quux::< + ParamOne, // Comment 1 + ParamTwo, // Comment 2 + >::some_func(); <*mut JSObject>::relocate(entry); diff --git a/tests/target/struct_tuple_visual.rs b/tests/target/struct_tuple_visual.rs index fa49c4f61a40..e63bc2c47c2b 100644 --- a/tests/target/struct_tuple_visual.rs +++ b/tests/target/struct_tuple_visual.rs @@ -10,7 +10,7 @@ fn foo() { // Comment foo(), // Comment // Comment - bar(), /* Comment */ + bar(), // Comment ); Foo(Bar, f()); @@ -24,7 +24,7 @@ fn foo() { Baz( xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, - zzzzz, /* test */ + zzzzz, // test ); A( diff --git a/tests/target/structs.rs b/tests/target/structs.rs index c525c5878454..dcb21bb195b5 100644 --- a/tests/target/structs.rs +++ b/tests/target/structs.rs @@ -41,7 +41,11 @@ pub struct Writebatch { struct NewType(Type, OtherType); -struct NewInt(pub i32, SomeType /* inline comment */, T /* sup */); +struct NewInt( + pub i32, + SomeType, // inline comment + T, // sup +); struct Qux< 'a, @@ -108,7 +112,10 @@ struct Baz { } // Will this be a one-liner? -struct Tuple(A /* Comment */, B); +struct Tuple( + A, // Comment + B, +); pub struct State time::Timespec> { now: F, @@ -157,10 +164,18 @@ struct Foo( TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU, ); -struct Foo(TTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT) +struct Foo( + TTTTTTTTTTTTTTTTTT, + UUUUUUUUUUUUUUUUUUUUUUUU, + TTTTTTTTTTTTTTTTTTT, +) where T: PartialEq; -struct Foo(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTTTT) +struct Foo( + TTTTTTTTTTTTTTTTT, + UUUUUUUUUUUUUUUUUUUUUUUU, + TTTTTTTTTTTTTTTTTTTTT, +) where T: PartialEq; struct Foo( diff --git a/tests/target/trailing_commas.rs b/tests/target/trailing_commas.rs index 4c4dedd59a04..93fcc0f2cb17 100644 --- a/tests/target/trailing_commas.rs +++ b/tests/target/trailing_commas.rs @@ -48,10 +48,7 @@ struct Pair< struct TupPair< S, T, ->( - S, - T, -) +>(S, T,) where T: P, S: P + Q;