]> git.proxmox.com Git - rustc.git/blame - src/test/ui-fulldeps/auxiliary/lint-tool-test.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui-fulldeps / auxiliary / lint-tool-test.rs
CommitLineData
c295e0f8 1#![feature(rustc_private)]
b7449926 2
74b04a01 3extern crate rustc_ast;
b7449926
XL
4
5// Load rustc as a plugin to get macros
416331ca 6extern crate rustc_driver;
74b04a01
XL
7#[macro_use]
8extern crate rustc_lint;
9#[macro_use]
10extern crate rustc_session;
b7449926 11
e1599b0c 12use rustc_driver::plugin::Registry;
74b04a01 13use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintId, LintPass};
3dfed10e 14use rustc_ast as ast;
b7449926 15declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff");
532ac7d7
XL
16declare_tool_lint!(
17 /// Some docs
18 pub clippy::TEST_GROUP,
19 Warn, "Warn about other stuff"
20);
b7449926 21
416331ca
XL
22declare_tool_lint!(
23 /// Some docs
24 pub rustc::TEST_RUSTC_TOOL_LINT,
25 Deny,
26 "Deny internal stuff"
27);
28
29declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]);
b7449926
XL
30
31impl EarlyLintPass for Pass {
32 fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
48663c56 33 if it.ident.name.as_str() == "lintme" {
2b03887a 34 cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span));
b7449926 35 }
48663c56 36 if it.ident.name.as_str() == "lintmetoo" {
2b03887a 37 cx.lint(TEST_GROUP, "item is named 'lintmetoo'", |lint| lint.set_span(it.span));
b7449926
XL
38 }
39 }
40}
41
94222f64
XL
42#[no_mangle]
43fn __rustc_plugin_registrar(reg: &mut Registry) {
e74abb32 44 reg.lint_store.register_lints(&[&TEST_RUSTC_TOOL_LINT, &TEST_LINT, &TEST_GROUP]);
c295e0f8 45 reg.lint_store.register_early_pass(|| Box::new(Pass));
74b04a01
XL
46 reg.lint_store.register_group(
47 true,
48 "clippy::group",
49 Some("clippy_group"),
50 vec![LintId::of(&TEST_LINT), LintId::of(&TEST_GROUP)],
51 );
b7449926 52}