]> git.lizzy.rs Git - rust.git/blob - tests/ui-internal/collapsible_span_lint_calls.fixed
Auto merge of #10146 - Nilstrieb:💀, r=llogiq
[rust.git] / tests / ui-internal / collapsible_span_lint_calls.fixed
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_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable);
37         span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
38         span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
39         span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
40         span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
41
42         // This expr shouldn't trigger this lint.
43         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
44             db.note(note_msg);
45             if predicate {
46                 db.note(note_msg);
47             }
48         });
49
50         // Issue #8798
51         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
52             db.help(help_msg).help(help_msg);
53         });
54     }
55 }
56
57 fn main() {}