2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2020-04-17 07:43:37 -05:00
|
|
|
#![deny(clippy::internal)]
|
2021-11-11 05:54:53 -06:00
|
|
|
#![allow(clippy::missing_clippy_version_attribute)]
|
2020-04-17 07:43:37 -05:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
|
2021-04-07 15:19:25 -05:00
|
|
|
extern crate clippy_utils;
|
2020-04-17 07:43:37 -05:00
|
|
|
extern crate rustc_ast;
|
|
|
|
extern crate rustc_errors;
|
|
|
|
extern crate rustc_lint;
|
|
|
|
extern crate rustc_session;
|
|
|
|
extern crate rustc_span;
|
|
|
|
|
2021-04-07 15:19:25 -05:00
|
|
|
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then};
|
2020-04-17 07:43:37 -05:00
|
|
|
use rustc_ast::ast::Expr;
|
2021-04-07 15:19:25 -05:00
|
|
|
use rustc_errors::Applicability;
|
|
|
|
use rustc_lint::{EarlyContext, EarlyLintPass};
|
2020-04-17 07:43:37 -05:00
|
|
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
|
|
|
|
|
|
|
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()";
|
|
|
|
let predicate = true;
|
|
|
|
|
|
|
|
span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable);
|
2020-04-18 05:28:29 -05:00
|
|
|
span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
|
|
|
|
span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
|
2020-04-18 05:29:36 -05:00
|
|
|
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
|
|
|
|
span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
|
2020-04-17 07:43:37 -05:00
|
|
|
|
|
|
|
// This expr shouldn't trigger this lint.
|
|
|
|
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
|
|
|
|
db.note(note_msg);
|
|
|
|
if predicate {
|
|
|
|
db.note(note_msg);
|
|
|
|
}
|
2022-06-19 23:17:54 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// Issue #8798
|
|
|
|
span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
|
|
|
|
db.help(help_msg).help(help_msg);
|
|
|
|
});
|
2020-04-17 07:43:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|