Skip to content

Commit 396a2af

Browse files
rchaser53topecongiro
authored andcommitted
fix to swallow attribute on brace expression (#3848)
1 parent 207a58f commit 396a2af

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/closures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use syntax::source_map::Span;
22
use syntax::{ast, ptr};
33

4+
use crate::attr::get_attrs_from_stmt;
45
use crate::config::lists::*;
56
use crate::config::Version;
67
use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond};
@@ -104,8 +105,13 @@ fn get_inner_expr<'a>(
104105

105106
// Figure out if a block is necessary.
106107
fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext<'_>) -> bool {
108+
let has_attributes = block.stmts.first().map_or(false, |first_stmt| {
109+
!get_attrs_from_stmt(first_stmt).is_empty()
110+
});
111+
107112
is_unsafe_block(block)
108113
|| block.stmts.len() > 1
114+
|| has_attributes
109115
|| block_contains_comment(block, context.source_map)
110116
|| prefix.contains('\n')
111117
}

tests/target/issue-3845.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
|| {
3+
#[allow(deprecated)]
4+
{
5+
u8::max_value()
6+
}
7+
};
8+
}

0 commit comments

Comments
 (0)