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