mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Merge pull request #519 from fhartwig/block-in-if-expr-false-positive
Don't trigger block_in_if_condition_expr lint if the block is unsafe
This commit is contained in:
commit
69c9edee54
@ -74,23 +74,25 @@ impl LateLintPass for BlockInIfCondition {
|
|||||||
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
|
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
|
||||||
if let ExprIf(ref check, ref then, _) = expr.node {
|
if let ExprIf(ref check, ref then, _) = expr.node {
|
||||||
if let ExprBlock(ref block) = check.node {
|
if let ExprBlock(ref block) = check.node {
|
||||||
if block.stmts.is_empty() {
|
if block.rules == DefaultBlock {
|
||||||
if let Some(ref ex) = block.expr {
|
if block.stmts.is_empty() {
|
||||||
// don't dig into the expression here, just suggest that they remove
|
if let Some(ref ex) = block.expr {
|
||||||
// the block
|
// don't dig into the expression here, just suggest that they remove
|
||||||
|
// the block
|
||||||
|
|
||||||
span_help_and_lint(cx, BLOCK_IN_IF_CONDITION_EXPR, check.span,
|
span_help_and_lint(cx, BLOCK_IN_IF_CONDITION_EXPR, check.span,
|
||||||
BRACED_EXPR_MESSAGE,
|
BRACED_EXPR_MESSAGE,
|
||||||
&format!("try\nif {} {} ... ", snippet_block(cx, ex.span, ".."),
|
&format!("try\nif {} {} ... ", snippet_block(cx, ex.span, ".."),
|
||||||
|
snippet_block(cx, then.span, "..")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// move block higher
|
||||||
|
span_help_and_lint(cx, BLOCK_IN_IF_CONDITION_STMT, check.span,
|
||||||
|
COMPLEX_BLOCK_MESSAGE,
|
||||||
|
&format!("try\nlet res = {};\nif res {} ... ",
|
||||||
|
snippet_block(cx, block.span, ".."),
|
||||||
snippet_block(cx, then.span, "..")));
|
snippet_block(cx, then.span, "..")));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// move block higher
|
|
||||||
span_help_and_lint(cx, BLOCK_IN_IF_CONDITION_STMT, check.span,
|
|
||||||
COMPLEX_BLOCK_MESSAGE,
|
|
||||||
&format!("try\nlet res = {};\nif res {} ... ",
|
|
||||||
snippet_block(cx, block.span, ".."),
|
|
||||||
snippet_block(cx, then.span, "..")));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut visitor = ExVisitor { found_block: None };
|
let mut visitor = ExVisitor { found_block: None };
|
||||||
|
@ -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() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user