From 7b3299e0094cdf407a3b745894a3949383c700f3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 12 Aug 2015 11:00:08 +0200 Subject: [PATCH] collapsible_if: do not show Debug display of expression Instead, pretty-print the inner block and use the same style as for the "single match => if let" lint. --- src/collapsible_if.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/collapsible_if.rs b/src/collapsible_if.rs index f1c82f3eef8..c30acc02a4e 100644 --- a/src/collapsible_if.rs +++ b/src/collapsible_if.rs @@ -18,8 +18,8 @@ use rustc::middle::def::*; use syntax::ast::*; use syntax::ptr::P; use syntax::codemap::{Span, Spanned, ExpnInfo}; -use syntax::print::pprust::expr_to_string; -use utils::{in_macro, span_lint}; +use syntax::print::pprust::{block_to_string, expr_to_string}; +use utils::{in_macro, span_help_and_lint}; declare_lint! { 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 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) { - span_lint(cx, COLLAPSIBLE_IF, e.span, &format!( - "this if statement can be collapsed. Try: `if {} && {}`\n{:?}", - check_to_string(check), check_to_string(check_inner), e)); + span_help_and_lint(cx, COLLAPSIBLE_IF, e.span, + "this if statement can be collapsed", + &format!("try\nif {} && {} {}", + check_to_string(check), check_to_string(check_inner), + block_to_string(&*content))); } } }