@@ -213,7 +213,6 @@ mod private {
213
213
#[ allow( private_interfaces) ]
214
214
pub trait Stage : Sized + ' static + Sealed {
215
215
type Id : Copy ;
216
- const SHOULD_EMIT_LINTS : bool ;
217
216
218
217
fn parsers ( ) -> & ' static group_type ! ( Self ) ;
219
218
@@ -222,13 +221,14 @@ pub trait Stage: Sized + 'static + Sealed {
222
221
sess : & ' sess Session ,
223
222
diag : impl for < ' x > Diagnostic < ' x > ,
224
223
) -> ErrorGuaranteed ;
224
+
225
+ fn should_emit ( & self ) -> ShouldEmit ;
225
226
}
226
227
227
228
// allow because it's a sealed trait
228
229
#[ allow( private_interfaces) ]
229
230
impl Stage for Early {
230
231
type Id = NodeId ;
231
- const SHOULD_EMIT_LINTS : bool = false ;
232
232
233
233
fn parsers ( ) -> & ' static group_type ! ( Self ) {
234
234
& early:: ATTRIBUTE_PARSERS
@@ -244,13 +244,16 @@ impl Stage for Early {
244
244
sess. dcx ( ) . create_err ( diag) . delay_as_bug ( )
245
245
}
246
246
}
247
+
248
+ fn should_emit ( & self ) -> ShouldEmit {
249
+ self . emit_errors
250
+ }
247
251
}
248
252
249
253
// allow because it's a sealed trait
250
254
#[ allow( private_interfaces) ]
251
255
impl Stage for Late {
252
256
type Id = HirId ;
253
- const SHOULD_EMIT_LINTS : bool = true ;
254
257
255
258
fn parsers ( ) -> & ' static group_type ! ( Self ) {
256
259
& late:: ATTRIBUTE_PARSERS
@@ -262,6 +265,10 @@ impl Stage for Late {
262
265
) -> ErrorGuaranteed {
263
266
tcx. dcx ( ) . emit_err ( diag)
264
267
}
268
+
269
+ fn should_emit ( & self ) -> ShouldEmit {
270
+ ShouldEmit :: ErrorsAndLints
271
+ }
265
272
}
266
273
267
274
/// used when parsing attributes for miscellaneous things *before* ast lowering
@@ -300,7 +307,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
300
307
/// must be delayed until after HIR is built. This method will take care of the details of
301
308
/// that.
302
309
pub ( crate ) fn emit_lint ( & mut self , lint : AttributeLintKind , span : Span ) {
303
- if !S :: SHOULD_EMIT_LINTS {
310
+ if !self . stage . should_emit ( ) . should_emit ( ) {
304
311
return ;
305
312
}
306
313
let id = self . target_id ;
@@ -657,14 +664,31 @@ impl<'sess> AttributeParser<'sess, Early> {
657
664
target_node_id : NodeId ,
658
665
features : Option < & ' sess Features > ,
659
666
) -> Option < Attribute > {
660
- let mut p = Self {
661
- features,
662
- tools : Vec :: new ( ) ,
663
- parse_only : Some ( sym) ,
667
+ let mut parsed = Self :: parse_limited_all (
664
668
sess,
665
- stage : Early { emit_errors : ShouldEmit :: Nothing } ,
666
- } ;
667
- let mut parsed = p. parse_attribute_list (
669
+ attrs,
670
+ Some ( sym) ,
671
+ target_span,
672
+ target_node_id,
673
+ features,
674
+ ShouldEmit :: Nothing ,
675
+ ) ;
676
+ assert ! ( parsed. len( ) <= 1 ) ;
677
+ parsed. pop ( )
678
+ }
679
+
680
+ pub fn parse_limited_all (
681
+ sess : & ' sess Session ,
682
+ attrs : & [ ast:: Attribute ] ,
683
+ parse_only : Option < Symbol > ,
684
+ target_span : Span ,
685
+ target_node_id : NodeId ,
686
+ features : Option < & ' sess Features > ,
687
+ emit_errors : ShouldEmit ,
688
+ ) -> Vec < Attribute > {
689
+ let mut p =
690
+ Self { features, tools : Vec :: new ( ) , parse_only, sess, stage : Early { emit_errors } } ;
691
+ p. parse_attribute_list (
668
692
attrs,
669
693
target_span,
670
694
target_node_id,
@@ -673,10 +697,7 @@ impl<'sess> AttributeParser<'sess, Early> {
673
697
|_lint| {
674
698
panic ! ( "can't emit lints here for now (nothing uses this atm)" ) ;
675
699
} ,
676
- ) ;
677
- assert ! ( parsed. len( ) <= 1 ) ;
678
-
679
- parsed. pop ( )
700
+ )
680
701
}
681
702
682
703
pub fn parse_single < T > (
0 commit comments