From 15ded04f46eef3a19cb2e843c6c084e63a2af009 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 14 Nov 2017 23:25:10 +0900 Subject: [PATCH 1/6] Update tests related to colon spacing --- .../configs-space_after_bound_colon-false.rs | 6 ----- .../configs-space_after_bound_colon-true.rs | 6 ----- ...pace_after_struct_lit_field_colon-false.rs | 6 ----- ...space_after_struct_lit_field_colon-true.rs | 6 ----- ...space_after_type_annotation_colon-false.rs | 6 ----- ...-space_after_type_annotation_colon-true.rs | 6 ----- .../configs-space_before_bound-false.rs | 6 ----- .../source/configs-space_before_bound-true.rs | 6 ----- .../source/configs-space_before_colon-true.rs | 11 ++++++++++ ...ace_before_struct_lit_field_colon-false.rs | 6 ----- ...pace_before_struct_lit_field_colon-true.rs | 6 ----- ...figs-space_before_type_annotation-false.rs | 6 ----- ...nfigs-space_before_type_annotation-true.rs | 6 ----- tests/source/space-before-bound.rs | 10 --------- tests/source/space-before-type-annotation.rs | 13 ----------- .../space-not-after-type-annotation-colon.rs | 14 ------------ tests/source/space-not-before-bound-colon.rs | 5 ----- .../configs-space_after_bound_colon-false.rs | 6 ----- .../configs-space_after_bound_colon-true.rs | 6 ----- ...pace_after_struct_lit_field_colon-false.rs | 6 ----- ...space_after_struct_lit_field_colon-true.rs | 6 ----- ...space_after_type_annotation_colon-false.rs | 6 ----- ...-space_after_type_annotation_colon-true.rs | 6 ----- .../configs-space_before_bound-false.rs | 6 ----- .../target/configs-space_before_bound-true.rs | 6 ----- .../target/configs-space_before_colon-true.rs | 11 ++++++++++ ...ace_before_struct_lit_field_colon-false.rs | 6 ----- ...pace_before_struct_lit_field_colon-true.rs | 6 ----- ...figs-space_before_type_annotation-false.rs | 6 ----- ...nfigs-space_before_type_annotation-true.rs | 6 ----- tests/target/space-before-bound.rs | 22 ------------------- tests/target/space-before-type-annotation.rs | 13 ----------- .../space-not-after-type-annotation-colon.rs | 14 ------------ tests/target/space-not-before-bound-colon.rs | 5 ----- 34 files changed, 22 insertions(+), 240 deletions(-) delete mode 100644 tests/source/configs-space_after_bound_colon-false.rs delete mode 100644 tests/source/configs-space_after_bound_colon-true.rs delete mode 100644 tests/source/configs-space_after_struct_lit_field_colon-false.rs delete mode 100644 tests/source/configs-space_after_struct_lit_field_colon-true.rs delete mode 100644 tests/source/configs-space_after_type_annotation_colon-false.rs delete mode 100644 tests/source/configs-space_after_type_annotation_colon-true.rs delete mode 100644 tests/source/configs-space_before_bound-false.rs delete mode 100644 tests/source/configs-space_before_bound-true.rs create mode 100644 tests/source/configs-space_before_colon-true.rs delete mode 100644 tests/source/configs-space_before_struct_lit_field_colon-false.rs delete mode 100644 tests/source/configs-space_before_struct_lit_field_colon-true.rs delete mode 100644 tests/source/configs-space_before_type_annotation-false.rs delete mode 100644 tests/source/configs-space_before_type_annotation-true.rs delete mode 100644 tests/source/space-before-bound.rs delete mode 100644 tests/source/space-before-type-annotation.rs delete mode 100644 tests/source/space-not-after-type-annotation-colon.rs delete mode 100644 tests/source/space-not-before-bound-colon.rs delete mode 100644 tests/target/configs-space_after_bound_colon-false.rs delete mode 100644 tests/target/configs-space_after_bound_colon-true.rs delete mode 100644 tests/target/configs-space_after_struct_lit_field_colon-false.rs delete mode 100644 tests/target/configs-space_after_struct_lit_field_colon-true.rs delete mode 100644 tests/target/configs-space_after_type_annotation_colon-false.rs delete mode 100644 tests/target/configs-space_after_type_annotation_colon-true.rs delete mode 100644 tests/target/configs-space_before_bound-false.rs delete mode 100644 tests/target/configs-space_before_bound-true.rs create mode 100644 tests/target/configs-space_before_colon-true.rs delete mode 100644 tests/target/configs-space_before_struct_lit_field_colon-false.rs delete mode 100644 tests/target/configs-space_before_struct_lit_field_colon-true.rs delete mode 100644 tests/target/configs-space_before_type_annotation-false.rs delete mode 100644 tests/target/configs-space_before_type_annotation-true.rs delete mode 100644 tests/target/space-before-bound.rs delete mode 100644 tests/target/space-before-type-annotation.rs delete mode 100644 tests/target/space-not-after-type-annotation-colon.rs delete mode 100644 tests/target/space-not-before-bound-colon.rs diff --git a/tests/source/configs-space_after_bound_colon-false.rs b/tests/source/configs-space_after_bound_colon-false.rs deleted file mode 100644 index 129d51048cca..000000000000 --- a/tests/source/configs-space_after_bound_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_bound_colon: false -// Space after bound colon - -fn lorem(t:T) { - // body -} diff --git a/tests/source/configs-space_after_bound_colon-true.rs b/tests/source/configs-space_after_bound_colon-true.rs deleted file mode 100644 index 32ebd52b1028..000000000000 --- a/tests/source/configs-space_after_bound_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_bound_colon: true -// Space after bound colon - -fn lorem(t:T) { - // body -} diff --git a/tests/source/configs-space_after_struct_lit_field_colon-false.rs b/tests/source/configs-space_after_struct_lit_field_colon-false.rs deleted file mode 100644 index 3ee99fa5d1d8..000000000000 --- a/tests/source/configs-space_after_struct_lit_field_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_struct_lit_field_colon: false - -const LOREM: Lorem = Lorem { - ipsum:dolor, - sit : amet, -}; diff --git a/tests/source/configs-space_after_struct_lit_field_colon-true.rs b/tests/source/configs-space_after_struct_lit_field_colon-true.rs deleted file mode 100644 index 6105d4725d8a..000000000000 --- a/tests/source/configs-space_after_struct_lit_field_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_struct_lit_field_colon: true - -const LOREM: Lorem = Lorem { - ipsum:dolor, - sit : amet, -}; diff --git a/tests/source/configs-space_after_type_annotation_colon-false.rs b/tests/source/configs-space_after_type_annotation_colon-false.rs deleted file mode 100644 index f814593a94e8..000000000000 --- a/tests/source/configs-space_after_type_annotation_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_type_annotation_colon: false -// Space after type annotation colon - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/source/configs-space_after_type_annotation_colon-true.rs b/tests/source/configs-space_after_type_annotation_colon-true.rs deleted file mode 100644 index 1a86a5879bdb..000000000000 --- a/tests/source/configs-space_after_type_annotation_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_type_annotation_colon: true -// Space after type annotation colon - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/source/configs-space_before_bound-false.rs b/tests/source/configs-space_before_bound-false.rs deleted file mode 100644 index f6168281c4fd..000000000000 --- a/tests/source/configs-space_before_bound-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_bound: false -// Space before bound - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/source/configs-space_before_bound-true.rs b/tests/source/configs-space_before_bound-true.rs deleted file mode 100644 index 7a16b5dbca3a..000000000000 --- a/tests/source/configs-space_before_bound-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_bound: true -// Space before bound - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/source/configs-space_before_colon-true.rs b/tests/source/configs-space_before_colon-true.rs new file mode 100644 index 000000000000..0a597602528a --- /dev/null +++ b/tests/source/configs-space_before_colon-true.rs @@ -0,0 +1,11 @@ +// rustfmt-space_before_colon: true +// Space before colon + +fn lorem(t : T) { + let ipsum: Dolor = sit; +} + +const LOREM : Lorem = Lorem { + ipsum : dolor, + sit : amet, +}; diff --git a/tests/source/configs-space_before_struct_lit_field_colon-false.rs b/tests/source/configs-space_before_struct_lit_field_colon-false.rs deleted file mode 100644 index a2d71c8bf0bc..000000000000 --- a/tests/source/configs-space_before_struct_lit_field_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_struct_lit_field_colon: false - -const LOREM: Lorem = Lorem { - ipsum:dolor, - sit : amet, -}; diff --git a/tests/source/configs-space_before_struct_lit_field_colon-true.rs b/tests/source/configs-space_before_struct_lit_field_colon-true.rs deleted file mode 100644 index 50e4ba12d82b..000000000000 --- a/tests/source/configs-space_before_struct_lit_field_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_struct_lit_field_colon: true - -const LOREM: Lorem = Lorem { - ipsum:dolor, - sit : amet, -}; diff --git a/tests/source/configs-space_before_type_annotation-false.rs b/tests/source/configs-space_before_type_annotation-false.rs deleted file mode 100644 index 817aa5c59408..000000000000 --- a/tests/source/configs-space_before_type_annotation-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_type_annotation: false -// Space before type-annotation - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/source/configs-space_before_type_annotation-true.rs b/tests/source/configs-space_before_type_annotation-true.rs deleted file mode 100644 index 4df9ad341e69..000000000000 --- a/tests/source/configs-space_before_type_annotation-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_type_annotation: true -// Space before type-annotation - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/source/space-before-bound.rs b/tests/source/space-before-bound.rs deleted file mode 100644 index 2a77eb2d2f92..000000000000 --- a/tests/source/space-before-bound.rs +++ /dev/null @@ -1,10 +0,0 @@ -// rustfmt-space_before_bound: true - -trait Trait {} -trait Trait2 {} -fn f<'a, 'b: 'a, T: Trait, U>() where U: Trait2 {} - -// should fit on the line -fn f2<'a, 'b: 'a, Ttttttttttttttttttttttttttttttttttttttttttttttt: Trait, U>() where U: Trait2 {} -// should be wrapped -fn f2<'a, 'b: 'a, Tttttttttttttttttttttttttttttttttttttttttttttttt: Trait, U>() where U: Trait2 {} diff --git a/tests/source/space-before-type-annotation.rs b/tests/source/space-before-type-annotation.rs deleted file mode 100644 index 15a75e4cf33b..000000000000 --- a/tests/source/space-before-type-annotation.rs +++ /dev/null @@ -1,13 +0,0 @@ -// rustfmt-space_before_type_annotation: true - -static staticVar: i32 = 42; -const constVar: i32 = 42; -fn foo(paramVar: i32) { - let localVar: i32 = 42; -} -struct S { - fieldVar: i32, -} -fn f() { - S { fieldVar: 42 } -} diff --git a/tests/source/space-not-after-type-annotation-colon.rs b/tests/source/space-not-after-type-annotation-colon.rs deleted file mode 100644 index 86f829c83538..000000000000 --- a/tests/source/space-not-after-type-annotation-colon.rs +++ /dev/null @@ -1,14 +0,0 @@ -// rustfmt-space_before_type_annotation: true -// rustfmt-space_after_type_annotation_colon: false - -static staticVar: i32 = 42; -const constVar: i32 = 42; -fn foo(paramVar: i32) { - let localVar: i32 = 42; -} -struct S { - fieldVar: i32, -} -fn f() { - S { fieldVar: 42 } -} diff --git a/tests/source/space-not-before-bound-colon.rs b/tests/source/space-not-before-bound-colon.rs deleted file mode 100644 index 4ec569f7902f..000000000000 --- a/tests/source/space-not-before-bound-colon.rs +++ /dev/null @@ -1,5 +0,0 @@ -// rustfmt-space_before_bound: true -// rustfmt-space_after_bound_colon: false - -trait Trait {} -fn f<'a, 'b: 'a, T: Trait>() {} diff --git a/tests/target/configs-space_after_bound_colon-false.rs b/tests/target/configs-space_after_bound_colon-false.rs deleted file mode 100644 index d254246b0f07..000000000000 --- a/tests/target/configs-space_after_bound_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_bound_colon: false -// Space after bound colon - -fn lorem(t: T) { - // body -} diff --git a/tests/target/configs-space_after_bound_colon-true.rs b/tests/target/configs-space_after_bound_colon-true.rs deleted file mode 100644 index 301b07dfa82a..000000000000 --- a/tests/target/configs-space_after_bound_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_bound_colon: true -// Space after bound colon - -fn lorem(t: T) { - // body -} diff --git a/tests/target/configs-space_after_struct_lit_field_colon-false.rs b/tests/target/configs-space_after_struct_lit_field_colon-false.rs deleted file mode 100644 index 8f4750594646..000000000000 --- a/tests/target/configs-space_after_struct_lit_field_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_struct_lit_field_colon: false - -const LOREM: Lorem = Lorem { - ipsum:dolor, - sit:amet, -}; diff --git a/tests/target/configs-space_after_struct_lit_field_colon-true.rs b/tests/target/configs-space_after_struct_lit_field_colon-true.rs deleted file mode 100644 index 34fb792dcb55..000000000000 --- a/tests/target/configs-space_after_struct_lit_field_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_struct_lit_field_colon: true - -const LOREM: Lorem = Lorem { - ipsum: dolor, - sit: amet, -}; diff --git a/tests/target/configs-space_after_type_annotation_colon-false.rs b/tests/target/configs-space_after_type_annotation_colon-false.rs deleted file mode 100644 index d27a5af37615..000000000000 --- a/tests/target/configs-space_after_type_annotation_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_type_annotation_colon: false -// Space after type annotation colon - -fn lorem(t:T) { - let ipsum:Dolor = sit; -} diff --git a/tests/target/configs-space_after_type_annotation_colon-true.rs b/tests/target/configs-space_after_type_annotation_colon-true.rs deleted file mode 100644 index ba0da25f836a..000000000000 --- a/tests/target/configs-space_after_type_annotation_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_after_type_annotation_colon: true -// Space after type annotation colon - -fn lorem(t: T) { - let ipsum: Dolor = sit; -} diff --git a/tests/target/configs-space_before_bound-false.rs b/tests/target/configs-space_before_bound-false.rs deleted file mode 100644 index 16e14bb77e3d..000000000000 --- a/tests/target/configs-space_before_bound-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_bound: false -// Space before bound - -fn lorem(t: T) { - let ipsum: Dolor = sit; -} diff --git a/tests/target/configs-space_before_bound-true.rs b/tests/target/configs-space_before_bound-true.rs deleted file mode 100644 index 3ee3dffb20ac..000000000000 --- a/tests/target/configs-space_before_bound-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_bound: true -// Space before bound - -fn lorem(t: T) { - let ipsum: Dolor = sit; -} diff --git a/tests/target/configs-space_before_colon-true.rs b/tests/target/configs-space_before_colon-true.rs new file mode 100644 index 000000000000..e2895b5d77b1 --- /dev/null +++ b/tests/target/configs-space_before_colon-true.rs @@ -0,0 +1,11 @@ +// rustfmt-space_before_colon: true +// Space before colon + +fn lorem(t : T) { + let ipsum : Dolor = sit; +} + +const LOREM : Lorem = Lorem { + ipsum : dolor, + sit : amet, +}; diff --git a/tests/target/configs-space_before_struct_lit_field_colon-false.rs b/tests/target/configs-space_before_struct_lit_field_colon-false.rs deleted file mode 100644 index 48336954786b..000000000000 --- a/tests/target/configs-space_before_struct_lit_field_colon-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_struct_lit_field_colon: false - -const LOREM: Lorem = Lorem { - ipsum: dolor, - sit: amet, -}; diff --git a/tests/target/configs-space_before_struct_lit_field_colon-true.rs b/tests/target/configs-space_before_struct_lit_field_colon-true.rs deleted file mode 100644 index e4f1cdb4575f..000000000000 --- a/tests/target/configs-space_before_struct_lit_field_colon-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_struct_lit_field_colon: true - -const LOREM: Lorem = Lorem { - ipsum : dolor, - sit : amet, -}; diff --git a/tests/target/configs-space_before_type_annotation-false.rs b/tests/target/configs-space_before_type_annotation-false.rs deleted file mode 100644 index b75144f7ca66..000000000000 --- a/tests/target/configs-space_before_type_annotation-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_type_annotation: false -// Space before type-annotation - -fn lorem(t: T) { - let ipsum: Dolor = sit; -} diff --git a/tests/target/configs-space_before_type_annotation-true.rs b/tests/target/configs-space_before_type_annotation-true.rs deleted file mode 100644 index 355cf9f5db9a..000000000000 --- a/tests/target/configs-space_before_type_annotation-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-space_before_type_annotation: true -// Space before type-annotation - -fn lorem(t : T) { - let ipsum : Dolor = sit; -} diff --git a/tests/target/space-before-bound.rs b/tests/target/space-before-bound.rs deleted file mode 100644 index 538d0d41a5e7..000000000000 --- a/tests/target/space-before-bound.rs +++ /dev/null @@ -1,22 +0,0 @@ -// rustfmt-space_before_bound: true - -trait Trait {} -trait Trait2 {} -fn f<'a, 'b : 'a, T : Trait, U>() -where - U : Trait2, -{ -} - -// should fit on the line -fn f2<'a, 'b : 'a, Ttttttttttttttttttttttttttttttttttttttttttttttt : Trait, U>() -where - U : Trait2, -{ -} -// should be wrapped -fn f2<'a, 'b : 'a, Tttttttttttttttttttttttttttttttttttttttttttttttt : Trait, U>() -where - U : Trait2, -{ -} diff --git a/tests/target/space-before-type-annotation.rs b/tests/target/space-before-type-annotation.rs deleted file mode 100644 index 0ad06dbb70c3..000000000000 --- a/tests/target/space-before-type-annotation.rs +++ /dev/null @@ -1,13 +0,0 @@ -// rustfmt-space_before_type_annotation: true - -static staticVar : i32 = 42; -const constVar : i32 = 42; -fn foo(paramVar : i32) { - let localVar : i32 = 42; -} -struct S { - fieldVar : i32, -} -fn f() { - S { fieldVar: 42 } -} diff --git a/tests/target/space-not-after-type-annotation-colon.rs b/tests/target/space-not-after-type-annotation-colon.rs deleted file mode 100644 index b07620fb4c17..000000000000 --- a/tests/target/space-not-after-type-annotation-colon.rs +++ /dev/null @@ -1,14 +0,0 @@ -// rustfmt-space_before_type_annotation: true -// rustfmt-space_after_type_annotation_colon: false - -static staticVar :i32 = 42; -const constVar :i32 = 42; -fn foo(paramVar :i32) { - let localVar :i32 = 42; -} -struct S { - fieldVar :i32, -} -fn f() { - S { fieldVar: 42 } -} diff --git a/tests/target/space-not-before-bound-colon.rs b/tests/target/space-not-before-bound-colon.rs deleted file mode 100644 index ef48eca11149..000000000000 --- a/tests/target/space-not-before-bound-colon.rs +++ /dev/null @@ -1,5 +0,0 @@ -// rustfmt-space_before_bound: true -// rustfmt-space_after_bound_colon: false - -trait Trait {} -fn f<'a, 'b :'a, T :Trait>() {} From babc4797831367b18ca4bec32ad8b98c3074148b Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 14 Nov 2017 23:25:36 +0900 Subject: [PATCH 2/6] Use space_before_colon and space_after_colon --- src/config.rs | 14 ++------------ src/expr.rs | 5 +---- src/items.rs | 25 +++++++------------------ src/types.rs | 4 ++-- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/config.rs b/src/config.rs index 555a6a207fa3..1e990c68a9f2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -613,18 +613,8 @@ create_config! { indentation level as the match keyword"; match_pattern_separator_break_point: SeparatorPlace, SeparatorPlace::Back, false, "Put a match sub-patterns' separator in front or back."; - space_before_type_annotation: bool, false, false, - "Leave a space before the colon in a type annotation"; - space_after_type_annotation_colon: bool, true, false, - "Leave a space after the colon in a type annotation"; - space_before_struct_lit_field_colon: bool, false, false, - "Leave a space before the colon in a struct literal field"; - space_after_struct_lit_field_colon: bool, true, false, - "Leave a space after the colon in a struct literal field"; - space_before_bound: bool, false, false, - "Leave a space before the colon in a trait or lifetime bound"; - space_after_bound_colon: bool, true, false, - "Leave a space after the colon in a trait or lifetime bound"; + space_before_colon: bool, false, false, "Leave a space before the colon"; + space_after_colon: bool, true, false, "Leave a space after the colon"; spaces_around_ranges: bool, false, false, "Put spaces around the .. and ... range operators"; spaces_within_angle_brackets: bool, false, false, "Put spaces within non-empty generic arguments"; diff --git a/src/expr.rs b/src/expr.rs index 5aee87dbbb73..d9f210f2b8a3 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2348,10 +2348,7 @@ pub fn wrap_struct_field( } pub fn struct_lit_field_separator(config: &Config) -> &str { - colon_spaces( - config.space_before_struct_lit_field_colon(), - config.space_after_struct_lit_field_colon(), - ) + colon_spaces(config.space_before_colon(), config.space_after_colon()) } pub fn rewrite_field( diff --git a/src/items.rs b/src/items.rs index cd3cb48c4dbd..a01b692d6810 100644 --- a/src/items.rs +++ b/src/items.rs @@ -39,10 +39,7 @@ use vertical::rewrite_with_alignment; use visitor::FmtVisitor; fn type_annotation_separator(config: &Config) -> &str { - colon_spaces( - config.space_before_type_annotation(), - config.space_after_type_annotation_colon(), - ) + colon_spaces(config.space_before_colon(), config.space_after_colon()) } // Statements of the form @@ -1405,16 +1402,8 @@ pub fn rewrite_type_alias( fn type_annotation_spacing(config: &Config) -> (&str, &str) { ( - if config.space_before_type_annotation() { - " " - } else { - "" - }, - if config.space_after_type_annotation_colon() { - " " - } else { - "" - }, + if config.space_before_colon() { " " } else { "" }, + if config.space_after_colon() { " " } else { "" }, ) } @@ -1581,8 +1570,8 @@ fn rewrite_static( offset: Indent, ) -> Option { let colon = colon_spaces( - context.config.space_before_type_annotation(), - context.config.space_after_type_annotation_colon(), + context.config.space_before_colon(), + context.config.space_after_colon(), ); let prefix = format!( "{}{} {}{}{}", @@ -1701,11 +1690,11 @@ impl Rewrite for ast::Arg { .rewrite(context, Shape::legacy(shape.width, shape.indent))?; if !is_empty_infer(context, &*self.ty) { - if context.config.space_before_type_annotation() { + if context.config.space_before_colon() { result.push_str(" "); } result.push_str(":"); - if context.config.space_after_type_annotation_colon() { + if context.config.space_after_colon() { result.push_str(" "); } let overhead = last_line_width(&result); diff --git a/src/types.rs b/src/types.rs index d2e782db1aa7..c28afda38931 100644 --- a/src/types.rs +++ b/src/types.rs @@ -399,8 +399,8 @@ where fn type_bound_colon(context: &RewriteContext) -> &'static str { colon_spaces( - context.config.space_before_bound(), - context.config.space_after_bound_colon(), + context.config.space_before_colon(), + context.config.space_after_colon(), ) } From 575ae22a5f7a5d0b10214a43e3e52881472a9494 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 14 Nov 2017 23:37:27 +0900 Subject: [PATCH 3/6] Update tests related to spaces with parens and brackets --- ...figs-spaces_within_angle_brackets-false.rs | 6 - ...nfigs-spaces_within_angle_brackets-true.rs | 6 - .../configs-spaces_within_parens-false.rs | 6 - .../configs-spaces_within_parens-true.rs | 6 - ...spaces_within_parens_and_brackets-false.rs | 7 + ...-spaces_within_parens_and_brackets-true.rs | 133 ++++++++++++++++ ...igs-spaces_within_square_brackets-false.rs | 6 - ...figs-spaces_within_square_brackets-true.rs | 6 - tests/source/spaces-within-angle-brackets.rs | 57 ------- tests/source/spaces-within-parens.rs | 45 ------ tests/source/spaces-within-square-brackets.rs | 27 ---- ...figs-spaces_within_angle_brackets-false.rs | 6 - ...nfigs-spaces_within_angle_brackets-true.rs | 6 - .../configs-spaces_within_parens-false.rs | 6 - .../configs-spaces_within_parens-true.rs | 6 - ...spaces_within_parens_and_brackets-false.rs | 7 + ...-spaces_within_parens_and_brackets-true.rs | 145 ++++++++++++++++++ ...igs-spaces_within_square_brackets-false.rs | 6 - ...figs-spaces_within_square_brackets-true.rs | 6 - tests/target/spaces-within-angle-brackets.rs | 61 -------- tests/target/spaces-within-parens.rs | 45 ------ tests/target/spaces-within-square-brackets.rs | 35 ----- 22 files changed, 292 insertions(+), 342 deletions(-) delete mode 100644 tests/source/configs-spaces_within_angle_brackets-false.rs delete mode 100644 tests/source/configs-spaces_within_angle_brackets-true.rs delete mode 100644 tests/source/configs-spaces_within_parens-false.rs delete mode 100644 tests/source/configs-spaces_within_parens-true.rs create mode 100644 tests/source/configs-spaces_within_parens_and_brackets-false.rs create mode 100644 tests/source/configs-spaces_within_parens_and_brackets-true.rs delete mode 100644 tests/source/configs-spaces_within_square_brackets-false.rs delete mode 100644 tests/source/configs-spaces_within_square_brackets-true.rs delete mode 100644 tests/source/spaces-within-angle-brackets.rs delete mode 100644 tests/source/spaces-within-parens.rs delete mode 100644 tests/source/spaces-within-square-brackets.rs delete mode 100644 tests/target/configs-spaces_within_angle_brackets-false.rs delete mode 100644 tests/target/configs-spaces_within_angle_brackets-true.rs delete mode 100644 tests/target/configs-spaces_within_parens-false.rs delete mode 100644 tests/target/configs-spaces_within_parens-true.rs create mode 100644 tests/target/configs-spaces_within_parens_and_brackets-false.rs create mode 100644 tests/target/configs-spaces_within_parens_and_brackets-true.rs delete mode 100644 tests/target/configs-spaces_within_square_brackets-false.rs delete mode 100644 tests/target/configs-spaces_within_square_brackets-true.rs delete mode 100644 tests/target/spaces-within-angle-brackets.rs delete mode 100644 tests/target/spaces-within-parens.rs delete mode 100644 tests/target/spaces-within-square-brackets.rs diff --git a/tests/source/configs-spaces_within_angle_brackets-false.rs b/tests/source/configs-spaces_within_angle_brackets-false.rs deleted file mode 100644 index 3823216f4336..000000000000 --- a/tests/source/configs-spaces_within_angle_brackets-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_angle_brackets: false -// Spaces within angle-brackets - -fn lorem(t: T) { - // body -} diff --git a/tests/source/configs-spaces_within_angle_brackets-true.rs b/tests/source/configs-spaces_within_angle_brackets-true.rs deleted file mode 100644 index f2b97d7def35..000000000000 --- a/tests/source/configs-spaces_within_angle_brackets-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_angle_brackets: true -// Spaces within angle-brackets - -fn lorem(t: T) { - // body -} diff --git a/tests/source/configs-spaces_within_parens-false.rs b/tests/source/configs-spaces_within_parens-false.rs deleted file mode 100644 index 05c25584fe16..000000000000 --- a/tests/source/configs-spaces_within_parens-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_parens: false -// Spaces within parens - -fn lorem(t: T) { - let lorem = (ipsum, dolor); -} diff --git a/tests/source/configs-spaces_within_parens-true.rs b/tests/source/configs-spaces_within_parens-true.rs deleted file mode 100644 index 7f041d71f49f..000000000000 --- a/tests/source/configs-spaces_within_parens-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_parens: true -// Spaces within parens - -fn lorem(t: T) { - let lorem = (ipsum, dolor); -} diff --git a/tests/source/configs-spaces_within_parens_and_brackets-false.rs b/tests/source/configs-spaces_within_parens_and_brackets-false.rs new file mode 100644 index 000000000000..908373ca9b05 --- /dev/null +++ b/tests/source/configs-spaces_within_parens_and_brackets-false.rs @@ -0,0 +1,7 @@ +// rustfmt-spaces_within_parens_and_brackets: false +// Spaces within parens and brackets + +fn lorem(t: T) { + let lorem = (ipsum, dolor); + let lorem: [usize; 2] = [ipsum, dolor]; +} diff --git a/tests/source/configs-spaces_within_parens_and_brackets-true.rs b/tests/source/configs-spaces_within_parens_and_brackets-true.rs new file mode 100644 index 000000000000..2e3c92da2fc3 --- /dev/null +++ b/tests/source/configs-spaces_within_parens_and_brackets-true.rs @@ -0,0 +1,133 @@ +// rustfmt-spaces_within_parens_and_brackets: true +// Spaces within parens and brackets + +fn lorem(t: T) { + let lorem = (ipsum, dolor); + let lorem: [usize; 2] = [ipsum, dolor]; +} + +enum E { + A(u32), + B(u32, u32), + C(u32, u32, u32), + D(), +} + +struct TupleStruct0(); +struct TupleStruct1(u32); +struct TupleStruct2(u32, u32); + +fn fooEmpty() {} + +fn foo(e: E, _: u32) -> (u32, u32) { + // Tuples + let t1 = (); + let t2 = (1,); + let t3 = (1, 2); + + let ts0 = TupleStruct0(); + let ts1 = TupleStruct1(1); + let ts2 = TupleStruct2(1, 2); + + // Tuple pattern + let (a,b,c) = (1,2,3); + + // Expressions + let x = (1 + 2) * (3); + + // Function call + fooEmpty(); + foo(1, 2); + + // Pattern matching + match e { + A(_) => (), + B(_, _) => (), + C(..) => (), + D => (), + } + + (1,2) +} + +struct Foo { + i: T, +} + +struct Bar { + i: T, + e: E, +} + +struct Foo<'a> { + i: &'a str, +} + +enum E { + T(T), +} + +enum E { + T(T), + S(S), +} + +fn foo(a: T) { + foo::(10); +} + +fn foo(a: T, b: E) { + foo::(10, "bar"); +} + +fn foo(a: T, b: E) { + foo::(10, "bar"); + + let opt: Option; + let res: Result; +} + +fn foo<'a>(a: &'a str) { + foo("foo"); +} + +fn foo<'a, 'b>(a: &'a str, b: &'b str) { + foo("foo", "bar"); +} + +impl Foo { + fn bar() { + ::bar(); + } +} + +trait MyTrait {} +impl MyTrait for Foo {} + +fn foo() where for<'a> u32: 'a {} + +fn main() { + let arr: [i32; 5] = [1, 2, 3, 4, 5]; + let arr: [i32; 500] = [0; 500]; + + let v = vec![1, 2, 3]; + assert_eq!(arr, [1, 2, 3]); + + let i = arr[0]; + + let slice = &arr[1..2]; + + let line100_________________________________________________________________________ = [1, 2]; + let line101__________________________________________________________________________ = [1, 2]; + let line102___________________________________________________________________________ = [1, 2]; + let line103____________________________________________________________________________ = [1, 2]; + let line104_____________________________________________________________________________ = [1, 2]; + + let line100_____________________________________________________________________ = vec![1, 2]; + let line101______________________________________________________________________ = vec![1, 2]; + let line102_______________________________________________________________________ = vec![1, 2]; + let line103________________________________________________________________________ = vec![1, 2]; + let line104_________________________________________________________________________ = vec![1, 2]; +} + +fn f(slice: &[i32]) {} diff --git a/tests/source/configs-spaces_within_square_brackets-false.rs b/tests/source/configs-spaces_within_square_brackets-false.rs deleted file mode 100644 index 6410646aad65..000000000000 --- a/tests/source/configs-spaces_within_square_brackets-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_square_brackets: false -// Spaces within square-brackets - -fn main() { - let lorem: [usize; 2] = [ipsum, dolor]; -} diff --git a/tests/source/configs-spaces_within_square_brackets-true.rs b/tests/source/configs-spaces_within_square_brackets-true.rs deleted file mode 100644 index 8683fb5f1c69..000000000000 --- a/tests/source/configs-spaces_within_square_brackets-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_square_brackets: true -// Spaces within square-brackets - -fn main() { - let lorem: [usize; 2] = [ipsum, dolor]; -} diff --git a/tests/source/spaces-within-angle-brackets.rs b/tests/source/spaces-within-angle-brackets.rs deleted file mode 100644 index 73cab841e2e6..000000000000 --- a/tests/source/spaces-within-angle-brackets.rs +++ /dev/null @@ -1,57 +0,0 @@ -// rustfmt-spaces_within_angle_brackets: true - -struct Foo { - i: T, -} - -struct Bar { - i: T, - e: E, -} - -struct Foo<'a> { - i: &'a str, -} - -enum E { - T(T), -} - -enum E { - T(T), - S(S), -} - -fn foo(a: T) { - foo::(10); -} - -fn foo(a: T, b: E) { - foo::(10, "bar"); -} - -fn foo(a: T, b: E) { - foo::(10, "bar"); - - let opt: Option; - let res: Result; -} - -fn foo<'a>(a: &'a str) { - foo("foo"); -} - -fn foo<'a, 'b>(a: &'a str, b: &'b str) { - foo("foo", "bar"); -} - -impl Foo { - fn bar() { - ::bar(); - } -} - -trait MyTrait {} -impl MyTrait for Foo {} - -fn foo() where for<'a> u32: 'a {} diff --git a/tests/source/spaces-within-parens.rs b/tests/source/spaces-within-parens.rs deleted file mode 100644 index dba8d7cf0130..000000000000 --- a/tests/source/spaces-within-parens.rs +++ /dev/null @@ -1,45 +0,0 @@ -// rustfmt-spaces_within_parens: true - -enum E { - A(u32), - B(u32, u32), - C(u32, u32, u32), - D(), -} - -struct TupleStruct0(); -struct TupleStruct1(u32); -struct TupleStruct2(u32, u32); - -fn fooEmpty() {} - -fn foo(e: E, _: u32) -> (u32, u32) { - // Tuples - let t1 = (); - let t2 = (1,); - let t3 = (1, 2); - - let ts0 = TupleStruct0(); - let ts1 = TupleStruct1(1); - let ts2 = TupleStruct2(1, 2); - - // Tuple pattern - let (a,b,c) = (1,2,3); - - // Expressions - let x = (1 + 2) * (3); - - // Function call - fooEmpty(); - foo(1, 2); - - // Pattern matching - match e { - A(_) => (), - B(_, _) => (), - C(..) => (), - D => (), - } - - (1,2) -} diff --git a/tests/source/spaces-within-square-brackets.rs b/tests/source/spaces-within-square-brackets.rs deleted file mode 100644 index d0466cacdd54..000000000000 --- a/tests/source/spaces-within-square-brackets.rs +++ /dev/null @@ -1,27 +0,0 @@ -// rustfmt-spaces_within_square_brackets: true - -fn main() { - let arr: [i32; 5] = [1, 2, 3, 4, 5]; - let arr: [i32; 500] = [0; 500]; - - let v = vec![1, 2, 3]; - assert_eq!(arr, [1, 2, 3]); - - let i = arr[0]; - - let slice = &arr[1..2]; - - let line100_________________________________________________________________________ = [1, 2]; - let line101__________________________________________________________________________ = [1, 2]; - let line102___________________________________________________________________________ = [1, 2]; - let line103____________________________________________________________________________ = [1, 2]; - let line104_____________________________________________________________________________ = [1, 2]; - - let line100_____________________________________________________________________ = vec![1, 2]; - let line101______________________________________________________________________ = vec![1, 2]; - let line102_______________________________________________________________________ = vec![1, 2]; - let line103________________________________________________________________________ = vec![1, 2]; - let line104_________________________________________________________________________ = vec![1, 2]; -} - -fn f(slice: &[i32]) {} diff --git a/tests/target/configs-spaces_within_angle_brackets-false.rs b/tests/target/configs-spaces_within_angle_brackets-false.rs deleted file mode 100644 index 3823216f4336..000000000000 --- a/tests/target/configs-spaces_within_angle_brackets-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_angle_brackets: false -// Spaces within angle-brackets - -fn lorem(t: T) { - // body -} diff --git a/tests/target/configs-spaces_within_angle_brackets-true.rs b/tests/target/configs-spaces_within_angle_brackets-true.rs deleted file mode 100644 index fef5ac25a4df..000000000000 --- a/tests/target/configs-spaces_within_angle_brackets-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_angle_brackets: true -// Spaces within angle-brackets - -fn lorem< T: Eq >(t: T) { - // body -} diff --git a/tests/target/configs-spaces_within_parens-false.rs b/tests/target/configs-spaces_within_parens-false.rs deleted file mode 100644 index 05c25584fe16..000000000000 --- a/tests/target/configs-spaces_within_parens-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_parens: false -// Spaces within parens - -fn lorem(t: T) { - let lorem = (ipsum, dolor); -} diff --git a/tests/target/configs-spaces_within_parens-true.rs b/tests/target/configs-spaces_within_parens-true.rs deleted file mode 100644 index 2461afb70889..000000000000 --- a/tests/target/configs-spaces_within_parens-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_parens: true -// Spaces within parens - -fn lorem( t: T ) { - let lorem = ( ipsum, dolor ); -} diff --git a/tests/target/configs-spaces_within_parens_and_brackets-false.rs b/tests/target/configs-spaces_within_parens_and_brackets-false.rs new file mode 100644 index 000000000000..908373ca9b05 --- /dev/null +++ b/tests/target/configs-spaces_within_parens_and_brackets-false.rs @@ -0,0 +1,7 @@ +// rustfmt-spaces_within_parens_and_brackets: false +// Spaces within parens and brackets + +fn lorem(t: T) { + let lorem = (ipsum, dolor); + let lorem: [usize; 2] = [ipsum, dolor]; +} diff --git a/tests/target/configs-spaces_within_parens_and_brackets-true.rs b/tests/target/configs-spaces_within_parens_and_brackets-true.rs new file mode 100644 index 000000000000..343b8749d6f1 --- /dev/null +++ b/tests/target/configs-spaces_within_parens_and_brackets-true.rs @@ -0,0 +1,145 @@ +// rustfmt-spaces_within_parens_and_brackets: true +// Spaces within parens and brackets + +fn lorem< T: Eq >( t: T ) { + let lorem = ( ipsum, dolor ); + let lorem: [ usize; 2 ] = [ ipsum, dolor ]; +} + +enum E { + A( u32 ), + B( u32, u32 ), + C( u32, u32, u32 ), + D(), +} + +struct TupleStruct0(); +struct TupleStruct1( u32 ); +struct TupleStruct2( u32, u32 ); + +fn fooEmpty() {} + +fn foo( e: E, _: u32 ) -> ( u32, u32 ) { + // Tuples + let t1 = (); + let t2 = ( 1, ); + let t3 = ( 1, 2 ); + + let ts0 = TupleStruct0(); + let ts1 = TupleStruct1( 1 ); + let ts2 = TupleStruct2( 1, 2 ); + + // Tuple pattern + let ( a, b, c ) = ( 1, 2, 3 ); + + // Expressions + let x = ( 1 + 2 ) * ( 3 ); + + // Function call + fooEmpty(); + foo( 1, 2 ); + + // Pattern matching + match e { + A( _ ) => (), + B( _, _ ) => (), + C( .. ) => (), + D => (), + } + + ( 1, 2 ) +} + +struct Foo< T > { + i: T, +} + +struct Bar< T, E > { + i: T, + e: E, +} + +struct Foo< 'a > { + i: &'a str, +} + +enum E< T > { + T(T), +} + +enum E< T, S > { + T(T), + S(S), +} + +fn foo< T >(a: T) { + foo::< u32 >(10); +} + +fn foo< T, E >(a: T, b: E) { + foo::< u32, str >(10, "bar"); +} + +fn foo< T: Send, E: Send >(a: T, b: E) { + foo::< u32, str >(10, "bar"); + + let opt: Option< u32 >; + let res: Result< u32, String >; +} + +fn foo< 'a >(a: &'a str) { + foo("foo"); +} + +fn foo< 'a, 'b >(a: &'a str, b: &'b str) { + foo("foo", "bar"); +} + +impl Foo { + fn bar() { + < Foo as Foo >::bar(); + } +} + +trait MyTrait< A, D > {} +impl< A: Send, D: Send > MyTrait< A, D > for Foo {} + +fn foo() + where + for< 'a > u32: 'a, +{ +} + +fn main() { + let arr: [ i32; 5 ] = [ 1, 2, 3, 4, 5 ]; + let arr: [ i32; 500 ] = [ 0; 500 ]; + + let v = vec![ 1, 2, 3 ]; + assert_eq!(arr, [ 1, 2, 3 ]); + + let i = arr[ 0 ]; + + let slice = &arr[ 1..2 ]; + + let line100_________________________________________________________________________ = [ 1, 2 ]; + let line101__________________________________________________________________________ = + [ 1, 2 ]; + let line102___________________________________________________________________________ = + [ 1, 2 ]; + let line103____________________________________________________________________________ = + [ 1, 2 ]; + let line104_____________________________________________________________________________ = + [ 1, 2 ]; + + let line100_____________________________________________________________________ = vec![ 1, 2 ]; + let line101______________________________________________________________________ = + vec![ 1, 2 ]; + let line102_______________________________________________________________________ = + vec![ 1, 2 ]; + let line103________________________________________________________________________ = + vec![ 1, 2 ]; + let line104_________________________________________________________________________ = + vec![ 1, 2 ]; +} + +fn f(slice: &[ i32 ]) {} diff --git a/tests/target/configs-spaces_within_square_brackets-false.rs b/tests/target/configs-spaces_within_square_brackets-false.rs deleted file mode 100644 index 6410646aad65..000000000000 --- a/tests/target/configs-spaces_within_square_brackets-false.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_square_brackets: false -// Spaces within square-brackets - -fn main() { - let lorem: [usize; 2] = [ipsum, dolor]; -} diff --git a/tests/target/configs-spaces_within_square_brackets-true.rs b/tests/target/configs-spaces_within_square_brackets-true.rs deleted file mode 100644 index 25f5e0e72315..000000000000 --- a/tests/target/configs-spaces_within_square_brackets-true.rs +++ /dev/null @@ -1,6 +0,0 @@ -// rustfmt-spaces_within_square_brackets: true -// Spaces within square-brackets - -fn main() { - let lorem: [ usize; 2 ] = [ ipsum, dolor ]; -} diff --git a/tests/target/spaces-within-angle-brackets.rs b/tests/target/spaces-within-angle-brackets.rs deleted file mode 100644 index 89335b602a42..000000000000 --- a/tests/target/spaces-within-angle-brackets.rs +++ /dev/null @@ -1,61 +0,0 @@ -// rustfmt-spaces_within_angle_brackets: true - -struct Foo< T > { - i: T, -} - -struct Bar< T, E > { - i: T, - e: E, -} - -struct Foo< 'a > { - i: &'a str, -} - -enum E< T > { - T(T), -} - -enum E< T, S > { - T(T), - S(S), -} - -fn foo< T >(a: T) { - foo::< u32 >(10); -} - -fn foo< T, E >(a: T, b: E) { - foo::< u32, str >(10, "bar"); -} - -fn foo< T: Send, E: Send >(a: T, b: E) { - foo::< u32, str >(10, "bar"); - - let opt: Option< u32 >; - let res: Result< u32, String >; -} - -fn foo< 'a >(a: &'a str) { - foo("foo"); -} - -fn foo< 'a, 'b >(a: &'a str, b: &'b str) { - foo("foo", "bar"); -} - -impl Foo { - fn bar() { - < Foo as Foo >::bar(); - } -} - -trait MyTrait< A, D > {} -impl< A: Send, D: Send > MyTrait< A, D > for Foo {} - -fn foo() -where - for< 'a > u32: 'a, -{ -} diff --git a/tests/target/spaces-within-parens.rs b/tests/target/spaces-within-parens.rs deleted file mode 100644 index 651386c618bf..000000000000 --- a/tests/target/spaces-within-parens.rs +++ /dev/null @@ -1,45 +0,0 @@ -// rustfmt-spaces_within_parens: true - -enum E { - A( u32 ), - B( u32, u32 ), - C( u32, u32, u32 ), - D(), -} - -struct TupleStruct0(); -struct TupleStruct1( u32 ); -struct TupleStruct2( u32, u32 ); - -fn fooEmpty() {} - -fn foo( e: E, _: u32 ) -> ( u32, u32 ) { - // Tuples - let t1 = (); - let t2 = ( 1, ); - let t3 = ( 1, 2 ); - - let ts0 = TupleStruct0(); - let ts1 = TupleStruct1( 1 ); - let ts2 = TupleStruct2( 1, 2 ); - - // Tuple pattern - let ( a, b, c ) = ( 1, 2, 3 ); - - // Expressions - let x = ( 1 + 2 ) * ( 3 ); - - // Function call - fooEmpty(); - foo( 1, 2 ); - - // Pattern matching - match e { - A( _ ) => (), - B( _, _ ) => (), - C( .. ) => (), - D => (), - } - - ( 1, 2 ) -} diff --git a/tests/target/spaces-within-square-brackets.rs b/tests/target/spaces-within-square-brackets.rs deleted file mode 100644 index cb468d6b59e6..000000000000 --- a/tests/target/spaces-within-square-brackets.rs +++ /dev/null @@ -1,35 +0,0 @@ -// rustfmt-spaces_within_square_brackets: true - -fn main() { - let arr: [ i32; 5 ] = [ 1, 2, 3, 4, 5 ]; - let arr: [ i32; 500 ] = [ 0; 500 ]; - - let v = vec![ 1, 2, 3 ]; - assert_eq!(arr, [ 1, 2, 3 ]); - - let i = arr[ 0 ]; - - let slice = &arr[ 1..2 ]; - - let line100_________________________________________________________________________ = [ 1, 2 ]; - let line101__________________________________________________________________________ = - [ 1, 2 ]; - let line102___________________________________________________________________________ = - [ 1, 2 ]; - let line103____________________________________________________________________________ = - [ 1, 2 ]; - let line104_____________________________________________________________________________ = - [ 1, 2 ]; - - let line100_____________________________________________________________________ = vec![ 1, 2 ]; - let line101______________________________________________________________________ = - vec![ 1, 2 ]; - let line102_______________________________________________________________________ = - vec![ 1, 2 ]; - let line103________________________________________________________________________ = - vec![ 1, 2 ]; - let line104_________________________________________________________________________ = - vec![ 1, 2 ]; -} - -fn f(slice: &[ i32 ]) {} From 94e22bb3340cf5056d79ee02674adda16c248aa7 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 14 Nov 2017 23:41:33 +0900 Subject: [PATCH 4/6] Fix typos --- ...-spaces_within_parens_and_brackets-true.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/target/configs-spaces_within_parens_and_brackets-true.rs b/tests/target/configs-spaces_within_parens_and_brackets-true.rs index 343b8749d6f1..7aff71315069 100644 --- a/tests/target/configs-spaces_within_parens_and_brackets-true.rs +++ b/tests/target/configs-spaces_within_parens_and_brackets-true.rs @@ -64,35 +64,35 @@ struct Foo< 'a > { } enum E< T > { - T(T), + T( T ), } enum E< T, S > { - T(T), - S(S), + T( T ), + S( S ), } -fn foo< T >(a: T) { - foo::< u32 >(10); +fn foo< T >( a: T ) { + foo::< u32 >( 10 ); } -fn foo< T, E >(a: T, b: E) { - foo::< u32, str >(10, "bar"); +fn foo< T, E >( a: T, b: E ) { + foo::< u32, str >( 10, "bar" ); } -fn foo< T: Send, E: Send >(a: T, b: E) { - foo::< u32, str >(10, "bar"); +fn foo< T: Send, E: Send >( a: T, b: E ) { + foo::< u32, str >( 10, "bar" ); let opt: Option< u32 >; let res: Result< u32, String >; } -fn foo< 'a >(a: &'a str) { - foo("foo"); +fn foo< 'a >( a: &'a str ) { + foo( "foo" ); } -fn foo< 'a, 'b >(a: &'a str, b: &'b str) { - foo("foo", "bar"); +fn foo< 'a, 'b >( a: &'a str, b: &'b str ) { + foo( "foo", "bar" ); } impl Foo { @@ -105,7 +105,7 @@ trait MyTrait< A, D > {} impl< A: Send, D: Send > MyTrait< A, D > for Foo {} fn foo() - where +where for< 'a > u32: 'a, { } @@ -115,7 +115,7 @@ fn main() { let arr: [ i32; 500 ] = [ 0; 500 ]; let v = vec![ 1, 2, 3 ]; - assert_eq!(arr, [ 1, 2, 3 ]); + assert_eq!( arr, [ 1, 2, 3 ] ); let i = arr[ 0 ]; @@ -142,4 +142,4 @@ fn main() { vec![ 1, 2 ]; } -fn f(slice: &[ i32 ]) {} +fn f( slice: &[ i32 ] ) {} From bc543cce0b4548730625a00bd7f3de1f58424a94 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 14 Nov 2017 23:42:31 +0900 Subject: [PATCH 5/6] Combine spaces_within_parens and spaces_within_brackets --- src/chains.rs | 11 ++++++----- src/config.rs | 7 ++----- src/expr.rs | 29 +++++++++++++++-------------- src/items.rs | 8 +++++--- src/macros.rs | 2 +- src/patterns.rs | 2 +- src/types.rs | 18 ++++++++++-------- src/utils.rs | 2 +- 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index 1a3586cd0441..c7b91625c981 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -485,11 +485,12 @@ fn rewrite_method_call( .map(|ty| ty.rewrite(context, shape)) .collect::>>()?; - let type_str = if context.config.spaces_within_angle_brackets() && !type_list.is_empty() { - format!("::< {} >", type_list.join(", ")) - } else { - format!("::<{}>", type_list.join(", ")) - }; + let type_str = + if context.config.spaces_within_parens_and_brackets() && !type_list.is_empty() { + format!("::< {} >", type_list.join(", ")) + } else { + format!("::<{}>", type_list.join(", ")) + }; (types.last().unwrap().span.hi(), type_str) }; diff --git a/src/config.rs b/src/config.rs index 1e990c68a9f2..c76933ca5097 100644 --- a/src/config.rs +++ b/src/config.rs @@ -616,11 +616,8 @@ create_config! { space_before_colon: bool, false, false, "Leave a space before the colon"; space_after_colon: bool, true, false, "Leave a space after the colon"; spaces_around_ranges: bool, false, false, "Put spaces around the .. and ... range operators"; - spaces_within_angle_brackets: bool, false, false, - "Put spaces within non-empty generic arguments"; - spaces_within_square_brackets: bool, false, false, - "Put spaces within non-empty square brackets"; - spaces_within_parens: bool, false, false, "Put spaces within non-empty parentheses"; + spaces_within_parens_and_brackets: bool, false, false, + "Put spaces within non-empty parentheses or brackets"; use_try_shorthand: bool, false, false, "Replace uses of the try! macro by the ? shorthand"; write_mode: WriteMode, WriteMode::Overwrite, false, "What Write Mode to use when none is supplied: \ diff --git a/src/expr.rs b/src/expr.rs index d9f210f2b8a3..077ba5271a4b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -202,7 +202,7 @@ pub fn format_expr( rewrite_index(&**expr, &**index, context, shape) } ast::ExprKind::Repeat(ref expr, ref repeats) => { - let (lbr, rbr) = if context.config.spaces_within_square_brackets() { + let (lbr, rbr) = if context.config.spaces_within_parens_and_brackets() { ("[ ", " ]") } else { ("[", "]") @@ -409,7 +409,7 @@ pub fn rewrite_array<'a, I>( where I: Iterator, { - let bracket_size = if context.config.spaces_within_square_brackets() { + let bracket_size = if context.config.spaces_within_parens_and_brackets() { 2 // "[ " } else { 1 // "[" @@ -439,7 +439,7 @@ where ).collect::>(); if items.is_empty() { - if context.config.spaces_within_square_brackets() { + if context.config.spaces_within_parens_and_brackets() { return Some("[ ]".to_string()); } else { return Some("[]".to_string()); @@ -501,7 +501,7 @@ where let result = if context.config.indent_style() == IndentStyle::Visual || tactic == DefinitiveListTactic::Horizontal { - if context.config.spaces_within_square_brackets() && !list_str.is_empty() { + if context.config.spaces_within_parens_and_brackets() && !list_str.is_empty() { format!("[ {} ]", list_str) } else { format!("[{}]", list_str) @@ -1801,7 +1801,7 @@ where T: Rewrite + Spanned + ToExpr + 'a, { // 2 = `( `, 1 = `(` - let paren_overhead = if context.config.spaces_within_parens() { + let paren_overhead = if context.config.spaces_within_parens_and_brackets() { 2 } else { 1 @@ -2098,7 +2098,7 @@ pub fn wrap_args_with_parens( || (context.inside_macro && !args_str.contains('\n') && args_str.len() + paren_overhead(context) <= shape.width) || is_extendable { - if context.config.spaces_within_parens() && !args_str.is_empty() { + if context.config.spaces_within_parens_and_brackets() && !args_str.is_empty() { format!("( {} )", args_str) } else { format!("({})", args_str) @@ -2141,11 +2141,12 @@ fn rewrite_paren(context: &RewriteContext, subexpr: &ast::Expr, shape: Shape) -> .offset_left(paren_overhead) .and_then(|s| s.sub_width(paren_overhead))?; - let paren_wrapper = |s: &str| if context.config.spaces_within_parens() && !s.is_empty() { - format!("( {} )", s) - } else { - format!("({})", s) - }; + let paren_wrapper = + |s: &str| if context.config.spaces_within_parens_and_brackets() && !s.is_empty() { + format!("( {} )", s) + } else { + format!("({})", s) + }; let subexpr_str = subexpr.rewrite(context, sub_shape)?; debug!("rewrite_paren, subexpr_str: `{:?}`", subexpr_str); @@ -2167,7 +2168,7 @@ fn rewrite_index( ) -> Option { let expr_str = expr.rewrite(context, shape)?; - let (lbr, rbr) = if context.config.spaces_within_square_brackets() { + let (lbr, rbr) = if context.config.spaces_within_parens_and_brackets() { ("[ ", " ]") } else { ("[", "]") @@ -2436,7 +2437,7 @@ where .unwrap() .rewrite(context, nested_shape) .map(|s| { - if context.config.spaces_within_parens() { + if context.config.spaces_within_parens_and_brackets() { format!("( {}, )", s) } else { format!("({},)", s) @@ -2476,7 +2477,7 @@ where }; let list_str = write_list(&item_vec, &fmt)?; - if context.config.spaces_within_parens() && !list_str.is_empty() { + if context.config.spaces_within_parens_and_brackets() && !list_str.is_empty() { Some(format!("( {} )", list_str)) } else { Some(format!("({})", list_str)) diff --git a/src/items.rs b/src/items.rs index a01b692d6810..fa697157ea32 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1882,7 +1882,9 @@ fn rewrite_fn_base( } else { result.push('('); } - if context.config.spaces_within_parens() && !fd.inputs.is_empty() && result.ends_with('(') { + if context.config.spaces_within_parens_and_brackets() && !fd.inputs.is_empty() + && result.ends_with('(') + { result.push(' ') } @@ -1943,7 +1945,7 @@ fn rewrite_fn_base( if fd.inputs.is_empty() && used_width + 1 > context.config.max_width() { result.push('\n'); } - if context.config.spaces_within_parens() && !fd.inputs.is_empty() { + if context.config.spaces_within_parens_and_brackets() && !fd.inputs.is_empty() { result.push(' ') } // If the last line of args contains comment, we cannot put the closing paren @@ -2522,7 +2524,7 @@ pub fn wrap_generics_with_angle_brackets( .block_unindent(context.config) .to_string(context.config) ) - } else if context.config.spaces_within_angle_brackets() { + } else if context.config.spaces_within_parens_and_brackets() { format!("< {} >", list_str) } else { format!("<{}>", list_str) diff --git a/src/macros.rs b/src/macros.rs index 8f5feac474c1..6e64a49361de 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -219,7 +219,7 @@ pub fn rewrite_macro( let mac_shape = shape.offset_left(macro_name.len())?; // Handle special case: `vec![expr; expr]` if vec_with_semi { - let (lbr, rbr) = if context.config.spaces_within_square_brackets() { + let (lbr, rbr) = if context.config.spaces_within_parens_and_brackets() { ("[ ", " ]") } else { ("[", "]") diff --git a/src/patterns.rs b/src/patterns.rs index a7e6c48b6d25..20ea14a5dfeb 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -109,7 +109,7 @@ impl Rewrite for Pat { let pats = pats?; // Unwrap all the sub-strings and join them with commas. - let result = if context.config.spaces_within_square_brackets() { + let result = if context.config.spaces_within_parens_and_brackets() { format!("[ {} ]", pats.join(", ")) } else { format!("[{}]", pats.join(", ")) diff --git a/src/types.rs b/src/types.rs index c28afda38931..180a38b2f23a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -54,7 +54,7 @@ pub fn rewrite_path( if let Some(qself) = qself { result.push('<'); - if context.config.spaces_within_angle_brackets() { + if context.config.spaces_within_parens_and_brackets() { result.push_str(" ") } @@ -81,7 +81,7 @@ pub fn rewrite_path( )?; } - if context.config.spaces_within_angle_brackets() { + if context.config.spaces_within_parens_and_brackets() { result.push_str(" ") } @@ -434,7 +434,9 @@ impl Rewrite for ast::WherePredicate { .collect::>>()?; let bounds_str = join_bounds(context, ty_shape, &bounds); - if context.config.spaces_within_angle_brackets() && !lifetime_str.is_empty() { + if context.config.spaces_within_parens_and_brackets() + && !lifetime_str.is_empty() + { format!( "for< {} > {}{}{}", lifetime_str, @@ -600,7 +602,7 @@ impl Rewrite for ast::PolyTraitRef { .rewrite(context, shape.offset_left(extra_offset)?)?; Some( - if context.config.spaces_within_angle_brackets() && !lifetime_str.is_empty() { + if context.config.spaces_within_parens_and_brackets() && !lifetime_str.is_empty() { format!("for< {} > {}", lifetime_str, path_str) } else { format!("for<{}> {}", lifetime_str, path_str) @@ -671,7 +673,7 @@ impl Rewrite for ast::Ty { let budget = shape.width.checked_sub(2)?; ty.rewrite(context, Shape::legacy(budget, shape.indent + 1)) .map(|ty_str| { - if context.config.spaces_within_parens() { + if context.config.spaces_within_parens_and_brackets() { format!("( {} )", ty_str) } else { format!("({})", ty_str) @@ -679,14 +681,14 @@ impl Rewrite for ast::Ty { }) } ast::TyKind::Slice(ref ty) => { - let budget = if context.config.spaces_within_square_brackets() { + let budget = if context.config.spaces_within_parens_and_brackets() { shape.width.checked_sub(4)? } else { shape.width.checked_sub(2)? }; ty.rewrite(context, Shape::legacy(budget, shape.indent + 1)) .map(|ty_str| { - if context.config.spaces_within_square_brackets() { + if context.config.spaces_within_parens_and_brackets() { format!("[ {} ]", ty_str) } else { format!("[{}]", ty_str) @@ -703,7 +705,7 @@ impl Rewrite for ast::Ty { rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape) } ast::TyKind::Array(ref ty, ref repeats) => { - let use_spaces = context.config.spaces_within_square_brackets(); + let use_spaces = context.config.spaces_within_parens_and_brackets(); let lbr = if use_spaces { "[ " } else { "[" }; let rbr = if use_spaces { " ]" } else { "]" }; rewrite_pair( diff --git a/src/utils.rs b/src/utils.rs index b87e2eaf493b..88272ff0d385 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -441,7 +441,7 @@ pub fn colon_spaces(before: bool, after: bool) -> &'static str { #[inline] pub fn paren_overhead(context: &RewriteContext) -> usize { - if context.config.spaces_within_parens() { + if context.config.spaces_within_parens_and_brackets() { 4 } else { 2 From 4e7c2756d3f4ffa983a74292b04080ea38107e02 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 14 Nov 2017 23:47:30 +0900 Subject: [PATCH 6/6] Update Configurations.md --- Configurations.md | 188 ++++++++++++---------------------------------- 1 file changed, 49 insertions(+), 139 deletions(-) diff --git a/Configurations.md b/Configurations.md index 31e5855bfaa8..9d74fd052505 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1719,9 +1719,9 @@ Don't reformat out of line modules - **Default value**: `false` - **Possible values**: `true`, `false` -## `space_after_bound_colon` +## `space_after_colon` -Leave a space after the colon in a trait or lifetime bound +Leave a space after the colon. - **Default value**: `true` - **Possible values**: `true`, `false` @@ -1730,19 +1730,56 @@ Leave a space after the colon in a trait or lifetime bound ```rust fn lorem(t: T) { - // body + let lorem: Dolor = Lorem { + ipsum: dolor, + sit: amet, + }; } ``` #### `false`: ```rust -fn lorem(t: T) { - // body +fn lorem(t:T) { + let lorem:Dolor = Lorem { + ipsum:dolor, + sit:amet, + }; } ``` -See also: [`space_before_bound`](#space_before_bound). +See also: [`space_before_colon`](#space_before_colon). + +## `space_before_colon` + +Leave a space before the colon. + +- **Default value**: `false` +- **Possible values**: `true`, `false` + +#### `false` (default): + +```rust +fn lorem(t: T) { + let lorem: Dolor = Lorem { + ipsum: dolor, + sit: amet, + }; +} +``` + +#### `true`: + +```rust +fn lorem(t : T) { + let lorem : Dolor = Lorem { + ipsum : dolor, + sit : amet, + }; +} +``` + +See also: [`space_after_colon`](#space_after_colon). ## `struct_field_align_threshold` @@ -1771,135 +1808,8 @@ struct Foo { } ``` -## `space_after_struct_lit_field_colon` - -Leave a space after the colon in a struct literal field - -- **Default value**: `true` -- **Possible values**: `true`, `false` - -#### `true` (default): - -```rust -let lorem = Lorem { - ipsum: dolor, - sit: amet, -}; ``` -#### `false`: - -```rust -let lorem = Lorem { - ipsum:dolor, - sit:amet, -}; -``` - -See also: [`space_before_struct_lit_field_colon`](#space_before_struct_lit_field_colon). - -## `space_after_type_annotation_colon` - -Leave a space after the colon in a type annotation - -- **Default value**: `true` -- **Possible values**: `true`, `false` - -#### `true` (default): - -```rust -fn lorem(t: T) { - let ipsum: Dolor = sit; -} -``` - -#### `false`: - -```rust -fn lorem(t:T) { - let ipsum:Dolor = sit; -} -``` - -See also: [`space_before_type_annotation`](#space_before_type_annotation). - -## `space_before_bound` - -Leave a space before the colon in a trait or lifetime bound - -- **Default value**: `false` -- **Possible values**: `true`, `false` - -#### `false` (default): - -```rust -fn lorem(t: T) { - let ipsum: Dolor = sit; -} -``` - -#### `true`: - -```rust -fn lorem(t: T) { - let ipsum: Dolor = sit; -} -``` - -See also: [`space_after_bound_colon`](#space_after_bound_colon). - -## `space_before_struct_lit_field_colon` - -Leave a space before the colon in a struct literal field - -- **Default value**: `false` -- **Possible values**: `true`, `false` - -#### `false` (default): - -```rust -let lorem = Lorem { - ipsum: dolor, - sit: amet, -}; -``` - -#### `true`: - -```rust -let lorem = Lorem { - ipsum : dolor, - sit : amet, -}; -``` - -See also: [`space_after_struct_lit_field_colon`](#space_after_struct_lit_field_colon). - -## `space_before_type_annotation` - -Leave a space before the colon in a type annotation - -- **Default value**: `false` -- **Possible values**: `true`, `false` - -#### `false` (default): - -```rust -fn lorem(t: T) { - let ipsum: Dolor = sit; -} -``` - -#### `true`: - -```rust -fn lorem(t : T) { - let ipsum : Dolor = sit; -} -``` - -See also: [`space_after_type_annotation_colon`](#space_after_type_annotation_colon). - ## `spaces_around_ranges` Put spaces around the .. and ... range operators @@ -1919,7 +1829,7 @@ let lorem = 0..10; let lorem = 0 .. 10; ``` -## `spaces_within_angle_brackets` +## `spaces_within_parens_and_brackets` Put spaces within non-empty generic arguments @@ -1942,9 +1852,9 @@ fn lorem< T: Eq >(t: T) { } ``` -See also: [`spaces_within_parens`](#spaces_within_parens), [`spaces_within_square_brackets`](#spaces_within_square_brackets). +See also: [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets), [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets). -## `spaces_within_parens` +## `spaces_within_parens_and_brackets` Put spaces within non-empty parentheses @@ -1967,9 +1877,9 @@ fn lorem( t: T ) { } ``` -See also: [`spaces_within_angle_brackets`](#spaces_within_angle_brackets), [`spaces_within_square_brackets`](#spaces_within_square_brackets). +See also: [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets), [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets). -## `spaces_within_square_brackets` +## `spaces_within_parens_and_brackets` Put spaces within non-empty square brackets @@ -1988,7 +1898,7 @@ let lorem: [usize; 2] = [ipsum, dolor]; let lorem: [ usize; 2 ] = [ ipsum, dolor ]; ``` -See also: [`spaces_within_parens`](#spaces_within_parens), [`spaces_within_angle_brackets`](#spaces_within_angle_brackets). +See also: [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets), [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets). ## `struct_lit_multiline_style`