From 596b4fa6b324efe28294a15d28fe350594634946 Mon Sep 17 00:00:00 2001 From: Jiri Bobek Date: Wed, 31 Jan 2024 15:03:01 +0100 Subject: [PATCH 1/2] Implement space_after_not option --- Configurations.md | 24 ++++++++++++++++++++++++ src/config/mod.rs | 1 + src/expr.rs | 7 ++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Configurations.md b/Configurations.md index 2d01fb3bb3b..cb318f37cfa 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..8299121df54 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"; 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> { From f66a86a77737e21e3986bfe2bea0af157e3826d6 Mon Sep 17 00:00:00 2001 From: Jiri Bobek Date: Wed, 31 Jan 2024 15:57:41 +0100 Subject: [PATCH 2/2] corrections --- Configurations.md | 2 +- src/config/mod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Configurations.md b/Configurations.md index cb318f37cfa..c7231921678 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2546,7 +2546,7 @@ fn lorem(t : T) { See also: [`space_after_colon`](#space_after_colon). -## `space_after_not +## `space_after_not` Leave a space after the `!` operator. diff --git a/src/config/mod.rs b/src/config/mod.rs index 8299121df54..029903fb95b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -660,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