2 #![deny(clippy::internal)]
3 #![feature(rustc_private)]
5 extern crate rustc_ast;
6 extern crate rustc_errors;
7 extern crate rustc_lint;
8 extern crate rustc_session;
9 extern crate rustc_span;
11 use rustc_ast::ast::Expr;
12 use rustc_errors::{Applicability, DiagnosticBuilder};
13 use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext};
14 use rustc_session::{declare_lint_pass, declare_tool_lint};
15 use rustc_span::source_map::Span;
17 #[allow(unused_variables)]
18 pub fn span_lint_and_then<'a, T: LintContext, F>(cx: &'a T, lint: &'static Lint, sp: Span, msg: &str, f: F)
20 F: for<'b> FnOnce(&mut DiagnosticBuilder<'b>),
24 #[allow(unused_variables)]
25 fn span_lint_and_help<'a, T: LintContext>(
30 option_span: Option<Span>,
35 #[allow(unused_variables)]
36 fn span_lint_and_note<'a, T: LintContext>(
41 note_span: Option<Span>,
46 #[allow(unused_variables)]
47 fn span_lint_and_sugg<'a, T: LintContext>(
54 applicability: Applicability,
59 pub clippy::TEST_LINT,
62 report_in_external_macro: true
65 declare_lint_pass!(Pass => [TEST_LINT]);
67 impl EarlyLintPass for Pass {
68 fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
69 let lint_msg = "lint message";
70 let help_msg = "help message";
71 let note_msg = "note message";
72 let sugg = "new_call()";
75 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
76 db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
78 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
79 db.span_help(expr.span, help_msg);
81 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
84 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
85 db.span_note(expr.span, note_msg);
87 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
91 // This expr shouldn't trigger this lint.
92 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {