Fix lint_without_lint_pass internal lint

This commit is contained in:
Philipp Krones 2024-11-03 14:25:46 +01:00
parent 4f12b98654
commit c64f1e3591
No known key found for this signature in database
GPG Key ID: 1CA0DF2AF59D68A5
2 changed files with 7 additions and 4 deletions

View File

@ -21,7 +21,7 @@
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// The compiler only knows lints via a `LintPass`. Without /// The compiler only knows lints via a `LintPass`. Without
/// putting a lint to a `LintPass::get_lints()`'s return, the compiler will not /// putting a lint to a `LintPass::lint_vec()`'s return, the compiler will not
/// know the name of the lint. /// know the name of the lint.
/// ///
/// ### Known problems /// ### Known problems
@ -159,8 +159,8 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
let body = cx.tcx.hir().body_owned_by( let body = cx.tcx.hir().body_owned_by(
impl_item_refs impl_item_refs
.iter() .iter()
.find(|iiref| iiref.ident.as_str() == "get_lints") .find(|iiref| iiref.ident.as_str() == "lint_vec")
.expect("LintPass needs to implement get_lints") .expect("LintPass needs to implement lint_vec")
.id .id
.owner_id .owner_id
.def_id, .def_id,

View File

@ -7,7 +7,7 @@
#[macro_use] #[macro_use]
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_lint; extern crate rustc_lint;
use rustc_lint::LintPass; use rustc_lint::{LintPass, LintVec};
declare_tool_lint! { declare_tool_lint! {
pub clippy::TEST_LINT, pub clippy::TEST_LINT,
@ -35,6 +35,9 @@ impl LintPass for Pass {
fn name(&self) -> &'static str { fn name(&self) -> &'static str {
"TEST_LINT" "TEST_LINT"
} }
fn get_lints(&self) -> LintVec {
vec![TEST_LINT]
}
} }
declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]); declare_lint_pass!(Pass2 => [TEST_LINT_REGISTERED]);