Skip to content

Commit

Permalink
fix to swallow attribute on brace expression (rust-lang#3848)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 authored and topecongiro committed Oct 10, 2019
1 parent 207a58f commit 396a2af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/closures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use syntax::source_map::Span;
use syntax::{ast, ptr};

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

// Figure out if a block is necessary.
fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext<'_>) -> bool {
let has_attributes = block.stmts.first().map_or(false, |first_stmt| {
!get_attrs_from_stmt(first_stmt).is_empty()
});

is_unsafe_block(block)
|| block.stmts.len() > 1
|| has_attributes
|| block_contains_comment(block, context.source_map)
|| prefix.contains('\n')
}
Expand Down
8 changes: 8 additions & 0 deletions tests/target/issue-3845.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
|| {
#[allow(deprecated)]
{
u8::max_value()
}
};
}

0 comments on commit 396a2af

Please sign in to comment.