fix to swallow attribute on brace expression (#3848)

This commit is contained in:
rChaser53 2019-10-10 10:35:34 +09:00 committed by Seiichi Uchida
parent 207a58f365
commit 396a2af181
2 changed files with 14 additions and 0 deletions

View File

@ -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};
@ -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')
}

View File

@ -0,0 +1,8 @@
fn main() {
|| {
#[allow(deprecated)]
{
u8::max_value()
}
};
}