@@ -203,10 +203,11 @@ mod private {
203203#[ allow( private_interfaces) ]
204204pub trait Stage : Sized + ' static + Sealed {
205205 type Id : Copy ;
206- const SHOULD_EMIT_LINTS : bool ;
207206
208207 fn parsers ( ) -> & ' static group_type ! ( Self ) ;
209208
209+ fn should_emit_errors_and_lints ( & self ) -> bool ;
210+
210211 fn emit_err < ' sess > (
211212 & self ,
212213 sess : & ' sess Session ,
@@ -218,11 +219,15 @@ pub trait Stage: Sized + 'static + Sealed {
218219#[ allow( private_interfaces) ]
219220impl Stage for Early {
220221 type Id = NodeId ;
221- const SHOULD_EMIT_LINTS : bool = false ;
222222
223223 fn parsers ( ) -> & ' static group_type ! ( Self ) {
224224 & early:: ATTRIBUTE_PARSERS
225225 }
226+
227+ fn should_emit_errors_and_lints ( & self ) -> bool {
228+ self . emit_errors . should_emit ( )
229+ }
230+
226231 fn emit_err < ' sess > (
227232 & self ,
228233 sess : & ' sess Session ,
@@ -240,11 +245,15 @@ impl Stage for Early {
240245#[ allow( private_interfaces) ]
241246impl Stage for Late {
242247 type Id = HirId ;
243- const SHOULD_EMIT_LINTS : bool = true ;
244248
245249 fn parsers ( ) -> & ' static group_type ! ( Self ) {
246250 & late:: ATTRIBUTE_PARSERS
247251 }
252+
253+ fn should_emit_errors_and_lints ( & self ) -> bool {
254+ true
255+ }
256+
248257 fn emit_err < ' sess > (
249258 & self ,
250259 tcx : & ' sess Session ,
@@ -290,7 +299,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
290299 /// must be delayed until after HIR is built. This method will take care of the details of
291300 /// that.
292301 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 ( ) {
294303 return ;
295304 }
296305 let id = self . target_id ;
@@ -712,6 +721,10 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
712721 & self . sess
713722 }
714723
724+ pub ( crate ) fn stage ( & self ) -> & S {
725+ & self . stage
726+ }
727+
715728 pub ( crate ) fn features ( & self ) -> & ' sess Features {
716729 self . features . expect ( "features not available at this point in the compiler" )
717730 }
0 commit comments