Merge pull request #2677 from csmoe/remove_nested_parens_opt
Add remove nested parens option
This commit is contained in:
commit
17b04f181d
@ -1270,6 +1270,28 @@ fn dolor() -> usize {}
|
||||
fn adipiscing() -> usize {}
|
||||
```
|
||||
|
||||
## `remove_nested_parens`
|
||||
|
||||
Remove nested parens.
|
||||
|
||||
- **Defalut value**: `false`,
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No
|
||||
|
||||
#### `false` (default):
|
||||
```rust
|
||||
fn main() {
|
||||
((((foo()))));
|
||||
}
|
||||
```
|
||||
|
||||
#### `true`:
|
||||
```rust
|
||||
fn main() {
|
||||
(foo());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## `reorder_imports`
|
||||
|
||||
|
@ -106,6 +106,8 @@ create_config! {
|
||||
"Maximum number of blank lines which can be put between items.";
|
||||
blank_lines_lower_bound: usize, 0, false,
|
||||
"Minimum number of blank lines which must be put between items.";
|
||||
remove_nested_parens: bool, false, false,
|
||||
"Remove nested parens.";
|
||||
|
||||
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
|
||||
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
|
||||
|
@ -1474,6 +1474,7 @@ fn rewrite_paren(
|
||||
// Extract comments within parens.
|
||||
let mut pre_comment;
|
||||
let mut post_comment;
|
||||
let remove_nested_parens = context.config.remove_nested_parens();
|
||||
loop {
|
||||
// 1 = "(" or ")"
|
||||
let pre_span = mk_sp(span.lo() + BytePos(1), subexpr.span.lo());
|
||||
@ -1483,7 +1484,7 @@ fn rewrite_paren(
|
||||
|
||||
// Remove nested parens if there are no comments.
|
||||
if let ast::ExprKind::Paren(ref subsubexpr) = subexpr.node {
|
||||
if pre_comment.is_empty() && post_comment.is_empty() {
|
||||
if remove_nested_parens && pre_comment.is_empty() && post_comment.is_empty() {
|
||||
span = subexpr.span;
|
||||
subexpr = subsubexpr;
|
||||
continue;
|
||||
|
@ -0,0 +1,5 @@
|
||||
// rustfmt-remove_nested_parens: true
|
||||
|
||||
fn main() {
|
||||
((((((foo()))))));
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-wrap_comments: true
|
||||
// rustfmt-remove_nested_parens: true
|
||||
// Test expressions
|
||||
|
||||
fn foo() -> bool {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Remove nested parens.
|
||||
// rustfmt-remove_nested_parens: true
|
||||
|
||||
fn main() {
|
||||
let x = (((1)));
|
||||
|
@ -0,0 +1,5 @@
|
||||
// rustfmt-remove_nested_parens: true
|
||||
|
||||
fn main() {
|
||||
(foo());
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-wrap_comments: true
|
||||
// rustfmt-remove_nested_parens: true
|
||||
// Test expressions
|
||||
|
||||
fn foo() -> bool {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Remove nested parens.
|
||||
// rustfmt-remove_nested_parens: true
|
||||
|
||||
fn main() {
|
||||
let x = (1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user