Merge pull request #2150 from topecongiro/audit-options/space

Combine spacing-related config options into a single general one
This commit is contained in:
Nick Cameron 2017-11-15 14:52:38 +13:00 committed by GitHub
commit f76b937e93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 416 additions and 795 deletions

View file

@ -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: Eq>(t: T) {
// body
let lorem: Dolor = Lorem {
ipsum: dolor,
sit: amet,
};
}
```
#### `false`:
```rust
fn lorem<T:Eq>(t: T) {
// body
fn lorem<T:Eq>(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: Eq>(t: T) {
let lorem: Dolor = Lorem {
ipsum: dolor,
sit: amet,
};
}
```
#### `true`:
```rust
fn lorem<T : Eq>(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: Eq>(t: T) {
let ipsum: Dolor = sit;
}
```
#### `false`:
```rust
fn lorem<T: Eq>(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: Eq>(t: T) {
let ipsum: Dolor = sit;
}
```
#### `true`:
```rust
fn lorem<T : Eq>(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: Eq>(t: T) {
let ipsum: Dolor = sit;
}
```
#### `true`:
```rust
fn lorem<T: Eq>(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: Eq>( 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`

View file

@ -485,11 +485,12 @@ fn rewrite_method_call(
.map(|ty| ty.rewrite(context, shape))
.collect::<Option<Vec<_>>>()?;
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)
};

View file

@ -613,24 +613,11 @@ 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";
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: \

View file

@ -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<Item = &'a ast::Expr>,
{
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::<Vec<_>>();
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<String> {
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 {
("[", "]")
@ -2348,10 +2349,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(
@ -2439,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)
@ -2479,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))

View file

@ -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<String> {
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);
@ -1893,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(' ')
}
@ -1954,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
@ -2533,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)

View file

@ -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 {
("[", "]")

View file

@ -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(", "))

View file

@ -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(" ")
}
@ -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(),
)
}
@ -434,7 +434,9 @@ impl Rewrite for ast::WherePredicate {
.collect::<Option<Vec<_>>>()?;
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(

View file

@ -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

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_bound_colon: false
// Space after bound colon
fn lorem<T:Eq>(t:T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_bound_colon: true
// Space after bound colon
fn lorem<T:Eq>(t:T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_struct_lit_field_colon: false
const LOREM: Lorem = Lorem {
ipsum:dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_struct_lit_field_colon: true
const LOREM: Lorem = Lorem {
ipsum:dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_type_annotation_colon: false
// Space after type annotation colon
fn lorem<T:Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_type_annotation_colon: true
// Space after type annotation colon
fn lorem<T:Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_bound: false
// Space before bound
fn lorem<T:Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_bound: true
// Space before bound
fn lorem<T:Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -0,0 +1,11 @@
// rustfmt-space_before_colon: true
// Space before colon
fn lorem<T : Eq>(t : T) {
let ipsum: Dolor = sit;
}
const LOREM : Lorem = Lorem {
ipsum : dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_struct_lit_field_colon: false
const LOREM: Lorem = Lorem {
ipsum:dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_struct_lit_field_colon: true
const LOREM: Lorem = Lorem {
ipsum:dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_type_annotation: false
// Space before type-annotation
fn lorem<T:Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_type_annotation: true
// Space before type-annotation
fn lorem<T:Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_angle_brackets: false
// Spaces within angle-brackets
fn lorem<T: Eq>(t: T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_angle_brackets: true
// Spaces within angle-brackets
fn lorem<T: Eq>(t: T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_parens: false
// Spaces within parens
fn lorem<T: Eq>(t: T) {
let lorem = (ipsum, dolor);
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_parens: true
// Spaces within parens
fn lorem<T: Eq>(t: T) {
let lorem = (ipsum, dolor);
}

View file

@ -0,0 +1,7 @@
// rustfmt-spaces_within_parens_and_brackets: false
// Spaces within parens and brackets
fn lorem<T: Eq>(t: T) {
let lorem = (ipsum, dolor);
let lorem: [usize; 2] = [ipsum, dolor];
}

View file

@ -0,0 +1,133 @@
// 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]) {}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_square_brackets: false
// Spaces within square-brackets
fn main() {
let lorem: [usize; 2] = [ipsum, dolor];
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_square_brackets: true
// Spaces within square-brackets
fn main() {
let lorem: [usize; 2] = [ipsum, dolor];
}

View file

@ -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 {}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -1,5 +0,0 @@
// rustfmt-space_before_bound: true
// rustfmt-space_after_bound_colon: false
trait Trait {}
fn f<'a, 'b: 'a, T: Trait>() {}

View file

@ -1,57 +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 {}

View file

@ -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)
}

View file

@ -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]) {}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_bound_colon: false
// Space after bound colon
fn lorem<T:Eq>(t: T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_bound_colon: true
// Space after bound colon
fn lorem<T: Eq>(t: T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_struct_lit_field_colon: false
const LOREM: Lorem = Lorem {
ipsum:dolor,
sit:amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_struct_lit_field_colon: true
const LOREM: Lorem = Lorem {
ipsum: dolor,
sit: amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_type_annotation_colon: false
// Space after type annotation colon
fn lorem<T: Eq>(t:T) {
let ipsum:Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_after_type_annotation_colon: true
// Space after type annotation colon
fn lorem<T: Eq>(t: T) {
let ipsum: Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_bound: false
// Space before bound
fn lorem<T: Eq>(t: T) {
let ipsum: Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_bound: true
// Space before bound
fn lorem<T : Eq>(t: T) {
let ipsum: Dolor = sit;
}

View file

@ -0,0 +1,11 @@
// rustfmt-space_before_colon: true
// Space before colon
fn lorem<T : Eq>(t : T) {
let ipsum : Dolor = sit;
}
const LOREM : Lorem = Lorem {
ipsum : dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_struct_lit_field_colon: false
const LOREM: Lorem = Lorem {
ipsum: dolor,
sit: amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_struct_lit_field_colon: true
const LOREM: Lorem = Lorem {
ipsum : dolor,
sit : amet,
};

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_type_annotation: false
// Space before type-annotation
fn lorem<T: Eq>(t: T) {
let ipsum: Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-space_before_type_annotation: true
// Space before type-annotation
fn lorem<T: Eq>(t : T) {
let ipsum : Dolor = sit;
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_angle_brackets: false
// Spaces within angle-brackets
fn lorem<T: Eq>(t: T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_angle_brackets: true
// Spaces within angle-brackets
fn lorem< T: Eq >(t: T) {
// body
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_parens: false
// Spaces within parens
fn lorem<T: Eq>(t: T) {
let lorem = (ipsum, dolor);
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_parens: true
// Spaces within parens
fn lorem<T: Eq>( t: T ) {
let lorem = ( ipsum, dolor );
}

View file

@ -0,0 +1,7 @@
// rustfmt-spaces_within_parens_and_brackets: false
// Spaces within parens and brackets
fn lorem<T: Eq>(t: T) {
let lorem = (ipsum, dolor);
let lorem: [usize; 2] = [ipsum, dolor];
}

View file

@ -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 ] ) {}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_square_brackets: false
// Spaces within square-brackets
fn main() {
let lorem: [usize; 2] = [ipsum, dolor];
}

View file

@ -1,6 +0,0 @@
// rustfmt-spaces_within_square_brackets: true
// Spaces within square-brackets
fn main() {
let lorem: [ usize; 2 ] = [ ipsum, dolor ];
}

View file

@ -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,
{
}

View file

@ -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 }
}

View file

@ -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 }
}

View file

@ -1,5 +0,0 @@
// rustfmt-space_before_bound: true
// rustfmt-space_after_bound_colon: false
trait Trait {}
fn f<'a, 'b :'a, T :Trait>() {}

View file

@ -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,
{
}

View file

@ -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 )
}

View file

@ -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 ]) {}