]> git.lizzy.rs Git - rust.git/blob - tests/ui/collapsible_span_lint_calls.fixed
Implement collapsible_span_lint_calls lint.
[rust.git] / tests / ui / collapsible_span_lint_calls.fixed
1 // run-rustfix
2 #![deny(clippy::internal)]
3 #![feature(rustc_private)]
4
5 extern crate rustc_ast;
6 extern crate rustc_errors;
7 extern crate rustc_lint;
8 extern crate rustc_session;
9 extern crate rustc_span;
10
11 use rustc_ast::ast::Expr;
12 use rustc_errors::{Applicability, DiagnosticBuilder};
13 use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext};
14 use rustc_session::{declare_lint_pass, declare_tool_lint};
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 #[allow(unused_variables)]
25 fn span_lint_and_help<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str) {}
26
27 #[allow(unused_variables)]
28 fn span_lint_and_note<'a, T: LintContext>(
29     cx: &'a T,
30     lint: &'static Lint,
31     span: Span,
32     msg: &str,
33     note_span: Span,
34     note: &str,
35 ) {
36 }
37
38 #[allow(unused_variables)]
39 fn span_lint_and_sugg<'a, T: LintContext>(
40     cx: &'a T,
41     lint: &'static Lint,
42     sp: Span,
43     msg: &str,
44     help: &str,
45     sugg: String,
46     applicability: Applicability,
47 ) {
48 }
49
50 declare_tool_lint! {
51     pub clippy::TEST_LINT,
52     Warn,
53     "",
54     report_in_external_macro: true
55 }
56
57 declare_lint_pass!(Pass => [TEST_LINT]);
58
59 impl EarlyLintPass for Pass {
60     fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
61         let lint_msg = "lint message";
62         let help_msg = "help message";
63         let note_msg = "note message";
64         let sugg = "new_call()";
65         let predicate = true;
66
67         span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable);
68         span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, help_msg);
69         span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, help_msg);
70         span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
71         span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, expr.span, note_msg);
72
73         // This expr shouldn't trigger this lint.
74         span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
75             db.note(note_msg);
76             if predicate {
77                 db.note(note_msg);
78             }
79         })
80     }
81 }
82
83 fn main() {}