Skip to content

Commit 8ba553c

Browse files
committed
Add test.
1 parent f3e2ccd commit 8ba553c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// run-rustfix
2+
#![deny(clippy::internal)]
3+
#![feature(rustc_private)]
4+
5+
extern crate rustc_session;
6+
extern crate rustc_errors;
7+
extern crate rustc_lint;
8+
extern crate syntax;
9+
extern crate rustc_span;
10+
11+
use rustc_session::{declare_tool_lint, declare_lint_pass};
12+
use rustc_errors::{DiagnosticBuilder, Applicability};
13+
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext, Lint};
14+
use syntax::ast::Expr;
15+
use rustc_span::source_map::Span;
16+
17+
pub fn span_lint_and_then<'a, T: LintContext, F>(cx: &'a T, lint: &'static Lint, sp: Span, msg: &str, f: F)
18+
where
19+
F: for<'b> FnOnce(&mut DiagnosticBuilder<'b>),
20+
{
21+
}
22+
23+
declare_tool_lint!{
24+
pub clippy::TEST_LINT,
25+
Warn,
26+
"",
27+
report_in_external_macro: true
28+
}
29+
30+
declare_lint_pass!(Pass => [TEST_LINT]);
31+
32+
impl EarlyLintPass for Pass {
33+
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
34+
let lint_msg = "lint message";
35+
let help_msg = "help message";
36+
let note_msg = "note message";
37+
let sugg = "new_call()";
38+
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
39+
db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
40+
});
41+
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
42+
db.span_help(expr.span, 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+
}
48+
}
49+
50+
fn main() {}

0 commit comments

Comments
 (0)