@@ -52,20 +52,23 @@ macro_rules! declare_forge_lint {
5252/// - `const REGISTERED_LINTS` containing all registered lint objects
5353#[ macro_export]
5454macro_rules! register_lints {
55- // 1. Internal rule for declaring structs.
56- ( @declare_structs $( ( $pass_id: ident, $pass_type: ident, $lints : tt ) ) ,* $( , ) ? ) => {
55+ // 1. Internal rule for declaring structs and their associated lints .
56+ ( @declare_structs $( ( $pass_id: ident, $pass_type: ident, ( $ ( $lint : expr ) , * $ ( , ) ? ) ) ) ,* $( , ) ? ) => {
5757 $(
5858 #[ derive( Debug , Default , Clone , Copy , Eq , PartialEq ) ]
5959 pub struct $pass_id;
6060
6161 impl $pass_id {
62+ /// Static slice of lints associated with this pass.
63+ const LINTS : & ' static [ SolLint ] = & [ $( $lint) ,* ] ;
64+
6265 register_lints!( @early_impl $pass_id, $pass_type) ;
6366 register_lints!( @late_impl $pass_id, $pass_type) ;
6467 }
6568 ) *
6669 } ;
6770
68- // 2. Internal rule for declaring the const array.
71+ // 2. Internal rule for declaring the const array of ALL lints .
6972 ( @declare_consts $( ( $pass_id: ident, $pass_type: ident, ( $( $lint: expr) ,* $( , ) ?) ) ) ,* $( , ) ? ) => {
7073 pub const REGISTERED_LINTS : & [ SolLint ] = & [
7174 $(
@@ -76,21 +79,21 @@ macro_rules! register_lints {
7679
7780 // 3. Internal rule for declaring the helper functions.
7881 ( @declare_funcs $( ( $pass_id: ident, $pass_type: ident, $lints: tt) ) ,* $( , ) ? ) => {
79- pub fn create_early_lint_passes<' a >( ) -> Vec <( Box <dyn EarlyLintPass <' a >>, SolLint ) > {
80- vec! [
82+ pub fn create_early_lint_passes<' ast >( ) -> Vec <( Box <dyn EarlyLintPass <' ast >>, & ' static [ SolLint ] ) > {
83+ [
8184 $(
82- register_lints!( @early_create $pass_id, $pass_type, $lints ) ,
85+ register_lints!( @early_create $pass_id, $pass_type) ,
8386 ) *
8487 ]
8588 . into_iter( )
8689 . flatten( )
8790 . collect( )
8891 }
8992
90- pub fn create_late_lint_passes<' hir>( ) -> Vec <( Box <dyn LateLintPass <' hir>>, SolLint ) > {
91- vec! [
93+ pub fn create_late_lint_passes<' hir>( ) -> Vec <( Box <dyn LateLintPass <' hir>>, & ' static [ SolLint ] ) > {
94+ [
9295 $(
93- register_lints!( @late_create $pass_id, $pass_type, $lints ) ,
96+ register_lints!( @late_create $pass_id, $pass_type) ,
9497 ) *
9598 ]
9699 . into_iter( )
@@ -114,14 +117,14 @@ macro_rules! register_lints {
114117 }
115118 } ;
116119
117- ( @early_create $_pass_id: ident, late, $_lints : tt ) => { vec! [ ] } ;
118- ( @early_create $pass_id: ident, $other : ident, ( $ ( $lint : expr ) , * ) ) => {
119- vec! [ $ ( ( $pass_id:: as_early_lint_pass( ) , $lint ) ) , * ]
120+ ( @early_create $_pass_id: ident, late) => { None } ;
121+ ( @early_create $pass_id: ident, $_other : ident) => {
122+ Some ( ( $pass_id:: as_early_lint_pass( ) , $pass_id :: LINTS ) )
120123 } ;
121124
122- ( @late_create $_pass_id: ident, early, $_lints : tt ) => { vec! [ ] } ;
123- ( @late_create $pass_id: ident, $other : ident, ( $ ( $lint : expr ) , * ) ) => {
124- vec! [ $ ( ( $pass_id:: as_late_lint_pass( ) , $lint ) ) , * ]
125+ ( @late_create $_pass_id: ident, early) => { None } ;
126+ ( @late_create $pass_id: ident, $_other : ident) => {
127+ Some ( ( $pass_id:: as_late_lint_pass( ) , $pass_id :: LINTS ) )
125128 } ;
126129
127130 // --- ENTRY POINT ---------------------------------------------------------
0 commit comments