-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41fda21
commit 1c2a87d
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// run-rustfix | ||
#![deny(clippy::internal)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_session; | ||
extern crate rustc_errors; | ||
extern crate rustc_lint; | ||
extern crate syntax; | ||
extern crate rustc_span; | ||
|
||
use rustc_session::{declare_tool_lint, declare_lint_pass}; | ||
use rustc_errors::{DiagnosticBuilder, Applicability}; | ||
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext, Lint}; | ||
use syntax::ast::Expr; | ||
use rustc_span::source_map::Span; | ||
|
||
#[allow(unused_variables)] | ||
pub fn span_lint_and_then<'a, T: LintContext, F>(cx: &'a T, lint: &'static Lint, sp: Span, msg: &str, f: F) | ||
where | ||
F: for<'b> FnOnce(&mut DiagnosticBuilder<'b>), | ||
{ | ||
} | ||
|
||
declare_tool_lint!{ | ||
pub clippy::TEST_LINT, | ||
Warn, | ||
"", | ||
report_in_external_macro: true | ||
} | ||
|
||
declare_lint_pass!(Pass => [TEST_LINT]); | ||
|
||
impl EarlyLintPass for Pass { | ||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) { | ||
let lint_msg = "lint message"; | ||
let help_msg = "help message"; | ||
let note_msg = "note message"; | ||
let sugg = "new_call()"; | ||
|
||
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { | ||
db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable); | ||
}); | ||
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { | ||
db.span_help(expr.span, help_msg); | ||
}); | ||
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| | ||
db.span_note(expr.span, note_msg) | ||
); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/collapsible_span_lint_calls.rs:44:13 | ||
| | ||
LL | db.span_help(expr.span, help_msg) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;` | ||
| | | ||
| expected `()`, found `&mut rustc_errors::DiagnosticBuilder<'_>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/collapsible_span_lint_calls.rs:47:13 | ||
| | ||
LL | db.span_note(expr.span, note_msg) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&mut rustc_errors::DiagnosticBuilder<'_>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |