mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 01:52:51 +00:00
Merge fn_empty_single_line and impl_empty_single_line into empty_item_single_line
This commit is contained in:
parent
9a33255834
commit
677446e99d
@ -874,10 +874,9 @@ struct Dolor<T>
|
||||
```
|
||||
|
||||
|
||||
## `empty_item_single_line`
|
||||
|
||||
## `fn_empty_single_line`
|
||||
|
||||
Put empty-body functions on a single line
|
||||
Put empty-body functions and impls on a single line
|
||||
|
||||
- **Default value**: `true`
|
||||
- **Possible values**: `true`, `false`
|
||||
@ -886,6 +885,8 @@ Put empty-body functions on a single line
|
||||
|
||||
```rust
|
||||
fn lorem() {}
|
||||
|
||||
impl Lorem {}
|
||||
```
|
||||
|
||||
#### `false`:
|
||||
@ -893,9 +894,12 @@ fn lorem() {}
|
||||
```rust
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
impl Lorem {
|
||||
}
|
||||
```
|
||||
|
||||
See also [`control_brace_style`](#control_brace_style).
|
||||
See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_style).
|
||||
|
||||
|
||||
## `fn_single_line`
|
||||
@ -1004,28 +1008,6 @@ fn lorem() -> usize {
|
||||
|
||||
See also: [`tab_spaces`](#tab_spaces).
|
||||
|
||||
## `impl_empty_single_line`
|
||||
|
||||
Put empty-body implementations on a single line
|
||||
|
||||
- **Default value**: `true`
|
||||
- **Possible values**: `true`, `false`
|
||||
|
||||
#### `true` (default):
|
||||
|
||||
```rust
|
||||
impl Lorem {}
|
||||
```
|
||||
|
||||
#### `false`:
|
||||
|
||||
```rust
|
||||
impl Lorem {
|
||||
}
|
||||
```
|
||||
|
||||
See also [`brace_style`](#brace_style).
|
||||
|
||||
|
||||
## `imports_indent`
|
||||
|
||||
|
@ -599,10 +599,10 @@ create_config! {
|
||||
normalize_comments: bool, false, true, "Convert /* */ comments to // comments where possible";
|
||||
|
||||
// Single line expressions and items.
|
||||
empty_item_single_line: bool, true, false,
|
||||
"Put empty-body functions and impls on a single line";
|
||||
struct_lit_single_line: bool, true, false,
|
||||
"Put small struct literals on a single line";
|
||||
impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";
|
||||
fn_empty_single_line: bool, true, false, "Put empty-body functions on a single line";
|
||||
fn_single_line: bool, false, false, "Put single-expression functions on a single line";
|
||||
where_single_line: bool, false, false, "To force single line where layout";
|
||||
|
||||
|
@ -366,7 +366,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
let codemap = self.get_context().codemap;
|
||||
|
||||
if self.config.fn_empty_single_line() && is_empty_block(block, codemap)
|
||||
if self.config.empty_item_single_line() && is_empty_block(block, codemap)
|
||||
&& self.block_indent.width() + fn_str.len() + 2 <= self.config.max_width()
|
||||
{
|
||||
return Some(format!("{}{{}}", fn_str));
|
||||
@ -705,7 +705,7 @@ fn is_impl_single_line(
|
||||
let open_pos = snippet.find_uncommented("{")? + 1;
|
||||
|
||||
Some(
|
||||
context.config.impl_empty_single_line() && items.is_empty() && !result.contains('\n')
|
||||
context.config.empty_item_single_line() && items.is_empty() && !result.contains('\n')
|
||||
&& result.len() + where_clause_str.len() <= context.config.max_width()
|
||||
&& !contains_comment(&snippet[open_pos..]),
|
||||
)
|
||||
|
17
tests/source/configs-empty_item_single_line-false.rs
Normal file
17
tests/source/configs-empty_item_single_line-false.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// rustfmt-empty_item_single_line: false
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {
|
||||
|
||||
}
|
||||
|
||||
impl Ipsum {
|
||||
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
|
||||
}
|
17
tests/source/configs-empty_item_single_line-true.rs
Normal file
17
tests/source/configs-empty_item_single_line-true.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// rustfmt-empty_item_single_line: true
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {
|
||||
|
||||
}
|
||||
|
||||
impl Ipsum {
|
||||
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// rustfmt-fn_empty_single_line: false
|
||||
// Empty function on single line
|
||||
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// rustfmt-fn_empty_single_line: true
|
||||
// Empty function on single line
|
||||
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// rustfmt-impl_empty_single_line: false
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {
|
||||
|
||||
}
|
||||
|
||||
impl Ipsum {
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// rustfmt-impl_empty_single_line: true
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {
|
||||
|
||||
}
|
||||
|
||||
impl Ipsum {
|
||||
|
||||
}
|
15
tests/target/configs-empty_item_single_line-false.rs
Normal file
15
tests/target/configs-empty_item_single_line-false.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// rustfmt-empty_item_single_line: false
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {
|
||||
}
|
||||
|
||||
impl Ipsum {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
|
||||
}
|
10
tests/target/configs-empty_item_single_line-true.rs
Normal file
10
tests/target/configs-empty_item_single_line-true.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// rustfmt-empty_item_single_line: true
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {}
|
||||
|
||||
impl Ipsum {}
|
||||
|
||||
fn lorem() {}
|
||||
|
||||
fn lorem() {}
|
@ -1,9 +0,0 @@
|
||||
// rustfmt-fn_empty_single_line: false
|
||||
// Empty function on single line
|
||||
|
||||
fn lorem() {
|
||||
}
|
||||
|
||||
fn lorem() {
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
// rustfmt-fn_empty_single_line: true
|
||||
// Empty function on single line
|
||||
|
||||
fn lorem() {}
|
||||
|
||||
fn lorem() {}
|
@ -1,8 +0,0 @@
|
||||
// rustfmt-impl_empty_single_line: false
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {
|
||||
}
|
||||
|
||||
impl Ipsum {
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
// rustfmt-impl_empty_single_line: true
|
||||
// Empty impl on single line
|
||||
|
||||
impl Lorem {}
|
||||
|
||||
impl Ipsum {}
|
Loading…
Reference in New Issue
Block a user