From 213c15cd66c2291bcb95c8f9bd421c5181cb68d3 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Wed, 9 Dec 2015 01:28:35 +0900 Subject: [PATCH] Add span_lint_and_then and use it --- src/eta_reduction.rs | 17 ++++++++++------- src/utils.rs | 11 +++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/eta_reduction.rs b/src/eta_reduction.rs index 5ade158200c..4957c2e21bc 100644 --- a/src/eta_reduction.rs +++ b/src/eta_reduction.rs @@ -2,7 +2,7 @@ use rustc::lint::*; use rustc_front::hir::*; use rustc::middle::ty; -use utils::{snippet_opt, span_lint, is_adjusted}; +use utils::{snippet_opt, span_lint_and_then, is_adjusted}; #[allow(missing_copy_implementations)] @@ -75,12 +75,15 @@ fn check_closure(cx: &LateContext, expr: &Expr) { return } } - span_lint(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found"); - if let Some(snippet) = snippet_opt(cx, caller.span) { - cx.sess().span_suggestion(expr.span, - "remove closure as shown:", - snippet); - } + span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, + "redundant closure found", + || { + if let Some(snippet) = snippet_opt(cx, caller.span) { + cx.sess().span_suggestion(expr.span, + "remove closure as shown:", + snippet); + } + }); } } } diff --git a/src/utils.rs b/src/utils.rs index 21d1f9d16ec..5e1671b709c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -325,6 +325,17 @@ pub fn span_note_and_lint(cx: &T, lint: &'static Lint, span: Spa } } +pub fn span_lint_and_then(cx: &T, lint: &'static Lint, sp: Span, + msg: &str, f: F) where F: Fn() { + cx.span_lint(lint, sp, msg); + if cx.current_level(lint) != Level::Allow { + f(); + cx.sess().fileline_help(sp, &format!("for further information visit \ + https://github.com/Manishearth/rust-clippy/wiki#{}", + lint.name_lower())) + } +} + /// return the base type for references and raw pointers pub fn walk_ptrs_ty(ty: ty::Ty) -> ty::Ty { match ty.sty {