diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui-fulldeps/auxiliary/lint-for-crate.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui-fulldeps/auxiliary/lint-for-crate.rs')
-rw-r--r-- | tests/ui-fulldeps/auxiliary/lint-for-crate.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/auxiliary/lint-for-crate.rs b/tests/ui-fulldeps/auxiliary/lint-for-crate.rs new file mode 100644 index 000000000..073da688c --- /dev/null +++ b/tests/ui-fulldeps/auxiliary/lint-for-crate.rs @@ -0,0 +1,45 @@ +// force-host + +#![feature(rustc_private)] + +extern crate rustc_driver; +extern crate rustc_hir; +#[macro_use] +extern crate rustc_lint; +#[macro_use] +extern crate rustc_session; +extern crate rustc_ast; +extern crate rustc_span; + +use rustc_driver::plugin::Registry; +use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_span::def_id::CRATE_DEF_ID; +use rustc_span::symbol::Symbol; + +declare_lint! { + CRATE_NOT_OKAY, + Warn, + "crate not marked with #![crate_okay]" +} + +declare_lint_pass!(Pass => [CRATE_NOT_OKAY]); + +impl<'tcx> LateLintPass<'tcx> for Pass { + fn check_crate(&mut self, cx: &LateContext) { + let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); + let span = cx.tcx.def_span(CRATE_DEF_ID); + if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) { + cx.lint( + CRATE_NOT_OKAY, + "crate is not marked with #![crate_okay]", + |lint| lint.set_span(span) + ); + } + } +} + +#[no_mangle] +fn __rustc_plugin_registrar(reg: &mut Registry) { + reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]); + reg.lint_store.register_late_pass(|_| Box::new(Pass)); +} |