Skip to content

Commit 320de71

Browse files
authored
Rollup merge of #72657 - flip1995:impl_lint_pass-ty, r=matthewjasper
Allow types (with lifetimes/generics) in impl_lint_pass cc rust-lang/rust-clippy#5279 (comment) This allows to implement `LintPass` for types with lifetimes and/or generics. The only thing, I'm not sure of is the `LintPass::name` function, which now includes the lifetime(s) (which will be `'_` most of the time) in the name returned for the lint pass, if it exists. But I don't think that this should be a problem, since the `LintPass::name` is never used for output for the user (?).
2 parents 5f0aefd + b124892 commit 320de71

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/librustc_session/lint.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,14 @@ pub trait LintPass {
347347
fn name(&self) -> &'static str;
348348
}
349349

350-
/// Implements `LintPass for $name` with the given list of `Lint` statics.
350+
/// Implements `LintPass for $ty` with the given list of `Lint` statics.
351351
#[macro_export]
352352
macro_rules! impl_lint_pass {
353-
($name:ident => [$($lint:expr),* $(,)?]) => {
354-
impl $crate::lint::LintPass for $name {
355-
fn name(&self) -> &'static str { stringify!($name) }
353+
($ty:ty => [$($lint:expr),* $(,)?]) => {
354+
impl $crate::lint::LintPass for $ty {
355+
fn name(&self) -> &'static str { stringify!($ty) }
356356
}
357-
impl $name {
357+
impl $ty {
358358
pub fn get_lints() -> $crate::lint::LintArray { $crate::lint_array!($($lint),*) }
359359
}
360360
};
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// compile-flags: -Z unstable-options
2+
// check-pass
3+
4+
#![feature(rustc_private)]
5+
6+
extern crate rustc_session;
7+
8+
use rustc_session::lint::{LintArray, LintPass};
9+
use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass};
10+
11+
declare_lint! {
12+
pub TEST_LINT,
13+
Allow,
14+
"test"
15+
}
16+
17+
struct Foo;
18+
19+
struct Bar<'a>(&'a u32);
20+
21+
impl_lint_pass!(Foo => [TEST_LINT]);
22+
impl_lint_pass!(Bar<'_> => [TEST_LINT]);
23+
24+
declare_lint_pass!(Baz => [TEST_LINT]);
25+
26+
fn main() {}

0 commit comments

Comments
 (0)