@@ -77,8 +77,9 @@ pub struct Lint {
77
77
/// e.g. "imports that are never used"
78
78
pub desc : & ' static str ,
79
79
80
- /// Deny lint after this edition
81
- pub edition_deny : Option < Edition > ,
80
+ /// Starting at the given edition, default to the given lint level. If this is `None`, then use
81
+ /// `default_level`.
82
+ pub edition_lint_opts : Option < ( Edition , Level ) > ,
82
83
}
83
84
84
85
impl Lint {
@@ -88,41 +89,40 @@ impl Lint {
88
89
}
89
90
90
91
pub fn default_level ( & self , session : & Session ) -> Level {
91
- if let Some ( edition_deny) = self . edition_deny {
92
- if session. edition ( ) >= edition_deny {
93
- return Level :: Deny
94
- }
95
- }
96
- self . default_level
92
+ self . edition_lint_opts
93
+ . filter ( |( e, _) | * e <= session. edition ( ) )
94
+ . map ( |( _, l) | l)
95
+ . unwrap_or ( self . default_level )
97
96
}
98
97
}
99
98
100
99
/// Declare a static item of type `&'static Lint`.
101
100
#[ macro_export]
102
101
macro_rules! declare_lint {
103
- ( $vis: vis $NAME: ident, $Level: ident, $desc: expr, $edition : expr ) => (
102
+ ( $vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
104
103
$vis static $NAME: & $crate:: lint:: Lint = & $crate:: lint:: Lint {
105
104
name: stringify!( $NAME) ,
106
105
default_level: $crate:: lint:: $Level,
107
106
desc: $desc,
108
- edition_deny : Some ( $edition )
107
+ edition_lint_opts : None ,
109
108
} ;
110
109
) ;
111
- ( $vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
110
+ ( $vis: vis $NAME: ident, $Level: ident, $desc: expr,
111
+ $lint_edition: expr => $edition_level: ident $( , ) ?
112
+ ) => (
112
113
$vis static $NAME: & $crate:: lint:: Lint = & $crate:: lint:: Lint {
113
114
name: stringify!( $NAME) ,
114
115
default_level: $crate:: lint:: $Level,
115
116
desc: $desc,
116
- edition_deny : None ,
117
+ edition_lint_opts : Some ( ( $lint_edition , $crate :: lint :: Level :: $edition_level ) ) ,
117
118
} ;
118
119
) ;
119
120
}
120
121
121
122
/// Declare a static `LintArray` and return it as an expression.
122
123
#[ macro_export]
123
124
macro_rules! lint_array {
124
- ( $( $lint: expr ) ,* , ) => { lint_array!( $( $lint ) ,* ) } ;
125
- ( $( $lint: expr ) ,* ) => { {
125
+ ( $( $lint: expr ) ,* $( , ) ?) => { {
126
126
static ARRAY : LintArray = & [ $( & $lint ) ,* ] ;
127
127
ARRAY
128
128
} }
0 commit comments