]> git.proxmox.com Git - rustc.git/blame - src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / test / ui-fulldeps / auxiliary / lint-group-plugin-test.rs
CommitLineData
1a4d82fc
JJ
1// force-host
2
3#![feature(plugin_registrar)]
c34b1796 4#![feature(box_syntax, rustc_private)]
1a4d82fc 5
0731742a 6// Load rustc as a plugin to get macros.
416331ca 7extern crate rustc_driver;
dfeec247 8extern crate rustc_hir;
74b04a01
XL
9#[macro_use]
10extern crate rustc_lint;
11#[macro_use]
12extern crate rustc_session;
1a4d82fc 13
e1599b0c 14use rustc_driver::plugin::Registry;
74b04a01 15use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintId, LintPass};
1a4d82fc
JJ
16
17declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
18
19declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
20
532ac7d7 21declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
1a4d82fc 22
476ff2be 23impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
dfeec247 24 fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
0731742a 25 match &*it.ident.as_str() {
74b04a01
XL
26 "lintme" => cx.lint(TEST_LINT, |lint| {
27 lint.build("item is named 'lintme'").set_span(it.span).emit()
28 }),
29 "pleaselintme" => cx.lint(PLEASE_LINT, |lint| {
30 lint.build("item is named 'pleaselintme'").set_span(it.span).emit()
31 }),
c1a9b12d 32 _ => {}
1a4d82fc
JJ
33 }
34 }
35}
36
37#[plugin_registrar]
38pub fn plugin_registrar(reg: &mut Registry) {
e74abb32
XL
39 reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
40 reg.lint_store.register_late_pass(|| box Pass);
74b04a01
XL
41 reg.lint_store.register_group(
42 true,
43 "lint_me",
44 None,
45 vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)],
46 );
1a4d82fc 47}