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