Skip to content

Commit

Permalink
docs: improve documentation of remove_nested_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
karolzwolak committed Feb 26, 2025
1 parent 0cdcf4b commit 8393df5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2235,32 +2235,34 @@ Works similarly to [`remove_nested_parens`](#remove_nested_parens), but removes
- **Possible values**: `true`, `false`
- **Stable**: No

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

#### `true`:
#### `false` (default):
```rust
fn main() {
{
foo();
{
// comment
{
foo();
}
}
}
}
```

#### `false` (default):
#### `true`:
```rust
fn main() {
{
// comment
{
{
{
foo();
}
}
foo();
}
}
}
```


## `reorder_impl_items`

Reorder impl items. `type` and `const` are put first, then macros and methods.
Expand Down
3 changes: 3 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,15 @@ fn rewrite_block_inner(
context: &RewriteContext<'_>,
shape: Shape,
can_be_removed: bool,
// ^ this is a fix for const blocks, which are not removed, but are passed identically to blocks
) -> RewriteResult {
debug!("rewrite_block : {:?}", context.snippet(block.span));
let prefix = block_prefix(context, block, shape)?;

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

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

0 comments on commit 8393df5

Please sign in to comment.