Skip to content

Commit 1c2a87d

Browse files
committed
Update reference.
1 parent 41fda21 commit 1c2a87d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
#[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+
declare_tool_lint!{
25+
pub clippy::TEST_LINT,
26+
Warn,
27+
"",
28+
report_in_external_macro: true
29+
}
30+
31+
declare_lint_pass!(Pass => [TEST_LINT]);
32+
33+
impl EarlyLintPass for Pass {
34+
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
35+
let lint_msg = "lint message";
36+
let help_msg = "help message";
37+
let note_msg = "note message";
38+
let sugg = "new_call()";
39+
40+
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
41+
db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
42+
});
43+
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
44+
db.span_help(expr.span, help_msg);
45+
});
46+
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db|
47+
db.span_note(expr.span, note_msg)
48+
);
49+
}
50+
}
51+
52+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/collapsible_span_lint_calls.rs:44:13
3+
|
4+
LL | db.span_help(expr.span, help_msg)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
6+
| |
7+
| expected `()`, found `&mut rustc_errors::DiagnosticBuilder<'_>`
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/collapsible_span_lint_calls.rs:47:13
11+
|
12+
LL | db.span_note(expr.span, note_msg)
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&mut rustc_errors::DiagnosticBuilder<'_>`
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)