Skip to content

Commit 8393df5

Browse files
committed
docs: improve documentation of remove_nested_blocks
1 parent 0cdcf4b commit 8393df5

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Configurations.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -2235,32 +2235,34 @@ Works similarly to [`remove_nested_parens`](#remove_nested_parens), but removes
22352235
- **Possible values**: `true`, `false`
22362236
- **Stable**: No
22372237

2238+
Blocks with any sort of comments or attributes, `unsafe` and `const` blocks will not be removed.
22382239

2239-
#### `true`:
2240+
#### `false` (default):
22402241
```rust
22412242
fn main() {
22422243
{
2243-
foo();
2244+
{
2245+
// comment
2246+
{
2247+
foo();
2248+
}
2249+
}
22442250
}
22452251
}
22462252
```
22472253

2248-
#### `false` (default):
2254+
#### `true`:
22492255
```rust
22502256
fn main() {
22512257
{
2258+
// comment
22522259
{
2253-
{
2254-
{
2255-
foo();
2256-
}
2257-
}
2260+
foo();
22582261
}
22592262
}
22602263
}
22612264
```
22622265

2263-
22642266
## `reorder_impl_items`
22652267

22662268
Reorder impl items. `type` and `const` are put first, then macros and methods.

src/expr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,15 @@ fn rewrite_block_inner(
676676
context: &RewriteContext<'_>,
677677
shape: Shape,
678678
can_be_removed: bool,
679+
// ^ this is a fix for const blocks, which are not removed, but are passed identically to blocks
679680
) -> RewriteResult {
680681
debug!("rewrite_block : {:?}", context.snippet(block.span));
681682
let prefix = block_prefix(context, block, shape)?;
682683

683684
let no_attrs = attrs.is_none() || attrs.unwrap().is_empty();
684685

686+
// If the option `remove_nested_blocks` is enabled, we remove all unnecessary nested blocks.
687+
// Blocks with any sort of comments or attributes, unsafe and const blocks will not be removed.
685688
if context.config.remove_nested_blocks()
686689
&& can_be_removed
687690
&& prefix.is_empty()

0 commit comments

Comments
 (0)