]> git.lizzy.rs Git - rust.git/blob - tests/ui-internal/collapsible_span_lint_calls.fixed
Use relative deps path
[rust.git] / tests / ui-internal / collapsible_span_lint_calls.fixed
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_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable);
36         span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
37         span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
38         span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
39         span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
40
41         // This expr shouldn't trigger this lint.
42         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
43             db.note(note_msg);
44             if predicate {
45                 db.note(note_msg);
46             }
47         })
48     }
49 }
50
51 fn main() {}