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)]
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);
+ }
+ });
}
}
}
}
}
+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 {