diff --git a/Configurations.md b/Configurations.md index 2d01fb3bb3b..c7231921678 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2546,6 +2546,30 @@ fn lorem(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 diff --git a/src/config/mod.rs b/src/config/mod.rs index 9484b2e5829..029903fb95b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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"; @@ -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 diff --git a/src/expr.rs b/src/expr.rs index 7808f891336..2e0d2a7019d 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1943,7 +1943,12 @@ fn rewrite_unary_op( shape: Shape, ) -> Option { // 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> {