@@ -5,7 +5,7 @@ use std::sync::LazyLock;
5
5
6
6
use private:: Sealed ;
7
7
use rustc_ast:: { AttrStyle , MetaItemLit , NodeId } ;
8
- use rustc_errors:: Diagnostic ;
8
+ use rustc_errors:: { Diag , Diagnostic , Level } ;
9
9
use rustc_feature:: AttributeTemplate ;
10
10
use rustc_hir:: attrs:: AttributeKind ;
11
11
use rustc_hir:: lints:: { AttributeLint , AttributeLintKind } ;
@@ -24,6 +24,7 @@ use crate::attributes::codegen_attrs::{
24
24
UsedParser ,
25
25
} ;
26
26
use crate :: attributes:: confusables:: ConfusablesParser ;
27
+ use crate :: attributes:: crate_level:: CrateNameParser ;
27
28
use crate :: attributes:: deprecation:: DeprecationParser ;
28
29
use crate :: attributes:: dummy:: DummyParser ;
29
30
use crate :: attributes:: inline:: { InlineParser , RustcForceInlineParser } ;
@@ -166,6 +167,7 @@ attribute_parsers!(
166
167
167
168
// tidy-alphabetical-start
168
169
Single <CoverageParser >,
170
+ Single <CrateNameParser >,
169
171
Single <CustomMirParser >,
170
172
Single <DeprecationParser >,
171
173
Single <DummyParser >,
@@ -263,11 +265,7 @@ impl Stage for Early {
263
265
sess : & ' sess Session ,
264
266
diag : impl for < ' x > Diagnostic < ' x > ,
265
267
) -> ErrorGuaranteed {
266
- if self . emit_errors . should_emit ( ) {
267
- sess. dcx ( ) . emit_err ( diag)
268
- } else {
269
- sess. dcx ( ) . create_err ( diag) . delay_as_bug ( )
270
- }
268
+ self . should_emit ( ) . emit_err ( sess. dcx ( ) . create_err ( diag) )
271
269
}
272
270
273
271
fn should_emit ( & self ) -> ShouldEmit {
@@ -314,7 +312,9 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
314
312
/// The span of the attribute currently being parsed
315
313
pub ( crate ) attr_span : Span ,
316
314
315
+ /// Whether it is an inner or outer attribute
317
316
pub ( crate ) attr_style : AttrStyle ,
317
+
318
318
/// The expected structure of the attribute.
319
319
///
320
320
/// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -333,7 +333,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
333
333
/// must be delayed until after HIR is built. This method will take care of the details of
334
334
/// that.
335
335
pub ( crate ) fn emit_lint ( & mut self , lint : AttributeLintKind , span : Span ) {
336
- if ! self . stage . should_emit ( ) . should_emit ( ) {
336
+ if matches ! ( self . stage. should_emit( ) , ShouldEmit :: Nothing ) {
337
337
return ;
338
338
}
339
339
let id = self . target_id ;
@@ -651,8 +651,13 @@ pub enum OmitDoc {
651
651
Skip ,
652
652
}
653
653
654
- #[ derive( Copy , Clone ) ]
654
+ #[ derive( Copy , Clone , Debug ) ]
655
655
pub enum ShouldEmit {
656
+ /// The operations will emit errors, and lints, and errors are fatal.
657
+ ///
658
+ /// Only relevant when early parsing, in late parsing equivalent to `ErrorsAndLints`.
659
+ /// Late parsing is never fatal, and instead tries to emit as many diagnostics as possible.
660
+ EarlyFatal ,
656
661
/// The operation will emit errors and lints.
657
662
/// This is usually what you need.
658
663
ErrorsAndLints ,
@@ -662,10 +667,12 @@ pub enum ShouldEmit {
662
667
}
663
668
664
669
impl ShouldEmit {
665
- pub fn should_emit ( & self ) -> bool {
670
+ pub ( crate ) fn emit_err ( & self , diag : Diag < ' _ > ) -> ErrorGuaranteed {
666
671
match self {
667
- ShouldEmit :: ErrorsAndLints => true ,
668
- ShouldEmit :: Nothing => false ,
672
+ ShouldEmit :: EarlyFatal if diag. level ( ) == Level :: DelayedBug => diag. emit ( ) ,
673
+ ShouldEmit :: EarlyFatal => diag. upgrade_to_fatal ( ) . emit ( ) ,
674
+ ShouldEmit :: ErrorsAndLints => diag. emit ( ) ,
675
+ ShouldEmit :: Nothing => diag. delay_as_bug ( ) ,
669
676
}
670
677
}
671
678
}
0 commit comments