]> git.lizzy.rs Git - rust.git/commitdiff
Add span_lint_and_then and use it
authorSeo Sanghyeon <sanxiyn@gmail.com>
Tue, 8 Dec 2015 16:28:35 +0000 (01:28 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Tue, 8 Dec 2015 17:46:14 +0000 (02:46 +0900)
src/eta_reduction.rs
src/utils.rs

index 5ade158200ced0bd7055f141629f6195b35e2730..4957c2e21bc6dfb66a63dd2ed288d4c8e6316de1 100644 (file)
@@ -2,7 +2,7 @@
 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);
+                    }
+                });
             }
         }
     }
index 21d1f9d16ec1f4fbd490ee9507954a887b8f906b..5e1671b709cb6ccf5b4787e0a1158c62802bf37a 100644 (file)
@@ -325,6 +325,17 @@ pub fn span_note_and_lint<T: LintContext>(cx: &T, lint: &'static Lint, span: Spa
     }
 }
 
+pub fn span_lint_and_then<T: LintContext, F>(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 {