Skip to content

Commit

Permalink
Update reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongmao86 committed Feb 11, 2020
1 parent 41fda21 commit 1c2a87d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/ui/collapsible_span_lint_calls.fixed
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() {}
17 changes: 17 additions & 0 deletions tests/ui/collapsible_span_lint_calls.stderr
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`.

0 comments on commit 1c2a87d

Please sign in to comment.