Skip to content

Commit 596b4fa

Browse files
committed
Implement space_after_not option
1 parent 5805040 commit 596b4fa

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Configurations.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,30 @@ fn lorem<T : Eq>(t : T) {
25462546

25472547
See also: [`space_after_colon`](#space_after_colon).
25482548

2549+
## `space_after_not
2550+
2551+
Leave a space after the `!` operator.
2552+
2553+
- **Default value**: `false`
2554+
- **Possible values**: `true`, `false`
2555+
- **Stable**: No
2556+
2557+
#### `false` (default):
2558+
2559+
```rust
2560+
fn not(b: bool) -> bool {
2561+
return !b;
2562+
}
2563+
```
2564+
2565+
#### `true`:
2566+
2567+
```rust
2568+
fn not(b: bool) -> bool {
2569+
return ! b;
2570+
}
2571+
```
2572+
25492573
## `spaces_around_ranges`
25502574

25512575
Put spaces around the .., ..=, and ... range operators

src/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ create_config! {
107107
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
108108
space_before_colon: bool, false, false, "Leave a space before the colon";
109109
space_after_colon: bool, true, false, "Leave a space after the colon";
110+
space_after_not: bool, false, false, "Leave a space after the `!` operator";
110111
spaces_around_ranges: bool, false, false, "Put spaces around the .. and ..= range operators";
111112
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
112113
"Where to put a binary operator when a binary expression goes multiline";

src/expr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,12 @@ fn rewrite_unary_op(
19431943
shape: Shape,
19441944
) -> Option<String> {
19451945
// For some reason, an UnOp is not spanned like BinOp!
1946-
rewrite_unary_prefix(context, op.as_str(), expr, shape)
1946+
match op {
1947+
ast::UnOp::Not if context.config.space_after_not() => {
1948+
rewrite_unary_prefix(context, format!("{} ", op.as_str()).as_str(), expr, shape)
1949+
}
1950+
_ => rewrite_unary_prefix(context, op.as_str(), expr, shape),
1951+
}
19471952
}
19481953

19491954
pub(crate) enum RhsAssignKind<'ast> {

0 commit comments

Comments
 (0)