Merge pull request #137 from birkenfeld/collapsible_if_fix

collapsible_if: do not show Debug display of expression
This commit is contained in:
Manish Goregaokar 2015-08-12 15:06:24 +05:30
commit 0481d04d6f

View File

@ -18,8 +18,8 @@ use rustc::middle::def::*;
use syntax::ast::*; use syntax::ast::*;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::codemap::{Span, Spanned, ExpnInfo}; use syntax::codemap::{Span, Spanned, ExpnInfo};
use syntax::print::pprust::expr_to_string; use syntax::print::pprust::{block_to_string, expr_to_string};
use utils::{in_macro, span_lint}; use utils::{in_macro, span_help_and_lint};
declare_lint! { declare_lint! {
pub COLLAPSIBLE_IF, pub COLLAPSIBLE_IF,
@ -45,11 +45,13 @@ fn check_expr_expd(cx: &Context, e: &Expr, info: Option<&ExpnInfo>) {
if in_macro(cx, info) { return; } if in_macro(cx, info) { return; }
if let ExprIf(ref check, ref then, None) = e.node { if let ExprIf(ref check, ref then, None) = e.node {
if let Some(&Expr{ node: ExprIf(ref check_inner, _, None), ..}) = if let Some(&Expr{ node: ExprIf(ref check_inner, ref content, None), ..}) =
single_stmt_of_block(then) { single_stmt_of_block(then) {
span_lint(cx, COLLAPSIBLE_IF, e.span, &format!( span_help_and_lint(cx, COLLAPSIBLE_IF, e.span,
"this if statement can be collapsed. Try: `if {} && {}`\n{:?}", "this if statement can be collapsed",
check_to_string(check), check_to_string(check_inner), e)); &format!("try\nif {} && {} {}",
check_to_string(check), check_to_string(check_inner),
block_to_string(&*content)));
} }
} }
} }