|
| 1 | +// run-rustfix |
| 2 | +#![deny(clippy::internal)] |
| 3 | +#![feature(rustc_private)] |
| 4 | + |
| 5 | +extern crate rustc_session; |
| 6 | +extern crate rustc_errors; |
| 7 | +extern crate rustc_lint; |
| 8 | +extern crate syntax; |
| 9 | +extern crate rustc_span; |
| 10 | + |
| 11 | +use rustc_session::{declare_tool_lint, declare_lint_pass}; |
| 12 | +use rustc_errors::{DiagnosticBuilder, Applicability}; |
| 13 | +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext, Lint}; |
| 14 | +use syntax::ast::Expr; |
| 15 | +use rustc_span::source_map::Span; |
| 16 | + |
| 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) |
| 19 | +where |
| 20 | + F: for<'b> FnOnce(&mut DiagnosticBuilder<'b>), |
| 21 | +{ |
| 22 | +} |
| 23 | + |
| 24 | +declare_tool_lint!{ |
| 25 | + pub clippy::TEST_LINT, |
| 26 | + Warn, |
| 27 | + "", |
| 28 | + report_in_external_macro: true |
| 29 | +} |
| 30 | + |
| 31 | +declare_lint_pass!(Pass => [TEST_LINT]); |
| 32 | + |
| 33 | +impl EarlyLintPass for Pass { |
| 34 | + fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) { |
| 35 | + let lint_msg = "lint message"; |
| 36 | + let help_msg = "help message"; |
| 37 | + let note_msg = "note message"; |
| 38 | + let sugg = "new_call()"; |
| 39 | + |
| 40 | + span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { |
| 41 | + db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable); |
| 42 | + }); |
| 43 | + span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { |
| 44 | + db.span_help(expr.span, help_msg); |
| 45 | + }); |
| 46 | + span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| |
| 47 | + db.span_note(expr.span, note_msg) |
| 48 | + ); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +fn main() {} |
0 commit comments