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