Don't trigger block_in_if_condition_expr lint if the block is unsafe

This commit is contained in:
Florian Hartwig 2015-12-23 02:12:08 +01:00
parent dd16ac2ad7
commit e4fbeb4947
2 changed files with 25 additions and 14 deletions

View file

@ -74,6 +74,7 @@ impl LateLintPass for BlockInIfCondition {
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
if let ExprIf(ref check, ref then, _) = expr.node {
if let ExprBlock(ref block) = check.node {
if block.rules == DefaultBlock {
if block.stmts.is_empty() {
if let Some(ref ex) = block.expr {
// don't dig into the expression here, just suggest that they remove
@ -92,6 +93,7 @@ impl LateLintPass for BlockInIfCondition {
snippet_block(cx, block.span, ".."),
snippet_block(cx, then.span, "..")));
}
}
} else {
let mut visitor = ExVisitor { found_block: None };
walk_expr(&mut visitor, check);

View file

@ -60,5 +60,14 @@ fn closure_without_block() {
}
}
fn condition_is_unsafe_block() {
let a: i32 = 1;
// this should not warn because the condition is an unsafe block
if unsafe { 1u32 == std::mem::transmute(a) } {
println!("1u32 == a");
}
}
fn main() {
}