Skip to content

Implement space_after_not option #6050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,30 @@ fn lorem<T : Eq>(t : T) {

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

## `space_after_not`

Leave a space after the `!` operator.

- **Default value**: `false`
- **Possible values**: `true`, `false`
- **Stable**: No

#### `false` (default):

```rust
fn not(b: bool) -> bool {
return !b;
}
```

#### `true`:

```rust
fn not(b: bool) -> bool {
return ! b;
}
```

## `spaces_around_ranges`

Put spaces around the .., ..=, and ... range operators
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ create_config! {
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
space_before_colon: bool, false, false, "Leave a space before the colon";
space_after_colon: bool, true, false, "Leave a space after the colon";
space_after_not: bool, false, false, "Leave a space after the `!` operator";
spaces_around_ranges: bool, false, false, "Put spaces around the .. and ..= range operators";
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
"Where to put a binary operator when a binary expression goes multiline";
Expand Down Expand Up @@ -659,6 +660,7 @@ reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
space_after_not = false
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
Expand Down
7 changes: 6 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,12 @@ fn rewrite_unary_op(
shape: Shape,
) -> Option<String> {
// For some reason, an UnOp is not spanned like BinOp!
rewrite_unary_prefix(context, op.as_str(), expr, shape)
match op {
ast::UnOp::Not if context.config.space_after_not() => {
rewrite_unary_prefix(context, format!("{} ", op.as_str()).as_str(), expr, shape)
}
_ => rewrite_unary_prefix(context, op.as_str(), expr, shape),
}
}

pub(crate) enum RhsAssignKind<'ast> {
Expand Down