]> git.lizzy.rs Git - rust.git/blob - tests/ui-internal/collapsible_span_lint_calls.rs
Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup
[rust.git] / tests / ui-internal / collapsible_span_lint_calls.rs
1 // run-rustfix
2 #![deny(clippy::internal)]
3 #![allow(clippy::missing_clippy_version_attribute)]
4 #![feature(rustc_private)]
5
6 extern crate clippy_utils;
7 extern crate rustc_ast;
8 extern crate rustc_errors;
9 extern crate rustc_lint;
10 extern crate rustc_session;
11 extern crate rustc_span;
12
13 use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then};
14 use rustc_ast::ast::Expr;
15 use rustc_errors::Applicability;
16 use rustc_lint::{EarlyContext, EarlyLintPass};
17 use rustc_session::{declare_lint_pass, declare_tool_lint};
18
19 declare_tool_lint! {
20     pub clippy::TEST_LINT,
21     Warn,
22     "",
23     report_in_external_macro: true
24 }
25
26 declare_lint_pass!(Pass => [TEST_LINT]);
27
28 impl EarlyLintPass for Pass {
29     fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
30         let lint_msg = "lint message";
31         let help_msg = "help message";
32         let note_msg = "note message";
33         let sugg = "new_call()";
34         let predicate = true;
35
36         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
37             db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
38         });
39         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
40             db.span_help(expr.span, help_msg);
41         });
42         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
43             db.help(help_msg);
44         });
45         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
46             db.span_note(expr.span, note_msg);
47         });
48         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
49             db.note(note_msg);
50         });
51
52         // This expr shouldn't trigger this lint.
53         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
54             db.note(note_msg);
55             if predicate {
56                 db.note(note_msg);
57             }
58         })
59     }
60 }
61
62 fn main() {}