]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/collapsible_span_lint_calls.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / collapsible_span_lint_calls.rs
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>(
26 cx: &'a T,
27 lint: &'static Lint,
28 span: Span,
29 msg: &str,
30 option_span: Option<Span>,
31 help: &str,
32 ) {
33 }
34
35 #[allow(unused_variables)]
36 fn span_lint_and_note<'a, T: LintContext>(
37 cx: &'a T,
38 lint: &'static Lint,
39 span: Span,
40 msg: &str,
41 note_span: Option<Span>,
42 note: &str,
43 ) {
44 }
45
46 #[allow(unused_variables)]
47 fn span_lint_and_sugg<'a, T: LintContext>(
48 cx: &'a T,
49 lint: &'static Lint,
50 sp: Span,
51 msg: &str,
52 help: &str,
53 sugg: String,
54 applicability: Applicability,
55 ) {
56 }
57
58 declare_tool_lint! {
59 pub clippy::TEST_LINT,
60 Warn,
61 "",
62 report_in_external_macro: true
63 }
64
65 declare_lint_pass!(Pass => [TEST_LINT]);
66
67 impl EarlyLintPass for Pass {
68 fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
69 let lint_msg = "lint message";
70 let help_msg = "help message";
71 let note_msg = "note message";
72 let sugg = "new_call()";
73 let predicate = true;
74
75 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
76 db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
77 });
78 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
79 db.span_help(expr.span, help_msg);
80 });
81 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
82 db.help(help_msg);
83 });
84 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
85 db.span_note(expr.span, note_msg);
86 });
87 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
88 db.note(note_msg);
89 });
90
91 // This expr shouldn't trigger this lint.
92 span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
93 db.note(note_msg);
94 if predicate {
95 db.note(note_msg);
96 }
97 })
98 }
99 }
100
101 fn main() {}