@@ -203,10 +203,11 @@ mod private {
203
203
#[ allow( private_interfaces) ]
204
204
pub trait Stage : Sized + ' static + Sealed {
205
205
type Id : Copy ;
206
- const SHOULD_EMIT_LINTS : bool ;
207
206
208
207
fn parsers ( ) -> & ' static group_type ! ( Self ) ;
209
208
209
+ fn should_emit_errors_and_lints ( & self ) -> bool ;
210
+
210
211
fn emit_err < ' sess > (
211
212
& self ,
212
213
sess : & ' sess Session ,
@@ -218,11 +219,15 @@ pub trait Stage: Sized + 'static + Sealed {
218
219
#[ allow( private_interfaces) ]
219
220
impl Stage for Early {
220
221
type Id = NodeId ;
221
- const SHOULD_EMIT_LINTS : bool = false ;
222
222
223
223
fn parsers ( ) -> & ' static group_type ! ( Self ) {
224
224
& early:: ATTRIBUTE_PARSERS
225
225
}
226
+
227
+ fn should_emit_errors_and_lints ( & self ) -> bool {
228
+ self . emit_errors . should_emit ( )
229
+ }
230
+
226
231
fn emit_err < ' sess > (
227
232
& self ,
228
233
sess : & ' sess Session ,
@@ -240,11 +245,15 @@ impl Stage for Early {
240
245
#[ allow( private_interfaces) ]
241
246
impl Stage for Late {
242
247
type Id = HirId ;
243
- const SHOULD_EMIT_LINTS : bool = true ;
244
248
245
249
fn parsers ( ) -> & ' static group_type ! ( Self ) {
246
250
& late:: ATTRIBUTE_PARSERS
247
251
}
252
+
253
+ fn should_emit_errors_and_lints ( & self ) -> bool {
254
+ true
255
+ }
256
+
248
257
fn emit_err < ' sess > (
249
258
& self ,
250
259
tcx : & ' sess Session ,
@@ -290,7 +299,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
290
299
/// must be delayed until after HIR is built. This method will take care of the details of
291
300
/// that.
292
301
pub ( crate ) fn emit_lint ( & mut self , lint : AttributeLintKind , span : Span ) {
293
- if !S :: SHOULD_EMIT_LINTS {
302
+ if !self . stage . should_emit_errors_and_lints ( ) {
294
303
return ;
295
304
}
296
305
let id = self . target_id ;
@@ -712,6 +721,10 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
712
721
& self . sess
713
722
}
714
723
724
+ pub ( crate ) fn stage ( & self ) -> & S {
725
+ & self . stage
726
+ }
727
+
715
728
pub ( crate ) fn features ( & self ) -> & ' sess Features {
716
729
self . features . expect ( "features not available at this point in the compiler" )
717
730
}
0 commit comments