3
3
use rustc_ast:: { self as ast, attr} ;
4
4
use rustc_ast:: { Attribute , LitKind , MetaItem , MetaItemKind , MetaItemLit , NestedMetaItem , NodeId } ;
5
5
use rustc_ast_pretty:: pprust;
6
+ use rustc_errors:: ErrorGuaranteed ;
6
7
use rustc_feature:: { find_gated_cfg, is_builtin_attr_name, Features , GatedCfg } ;
7
8
use rustc_macros:: HashStable_Generic ;
8
9
use rustc_session:: config:: ExpectedValues ;
@@ -367,19 +368,23 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
367
368
since = Some ( rust_version_symbol ( ) ) ;
368
369
}
369
370
371
+ let feature = match feature {
372
+ Some ( feature) if rustc_lexer:: is_ident ( feature. as_str ( ) ) => Ok ( feature) ,
373
+ Some ( _bad_feature) => {
374
+ Err ( sess. emit_err ( session_diagnostics:: NonIdentFeature { span : attr. span } ) )
375
+ }
376
+ None => Err ( sess. emit_err ( session_diagnostics:: MissingFeature { span : attr. span } ) ) ,
377
+ } ;
378
+
379
+ let since =
380
+ since. ok_or_else ( || sess. emit_err ( session_diagnostics:: MissingSince { span : attr. span } ) ) ;
381
+
370
382
match ( feature, since) {
371
- ( Some ( feature) , Some ( since) ) => {
383
+ ( Ok ( feature) , Ok ( since) ) => {
372
384
let level = StabilityLevel :: Stable { since, allowed_through_unstable_modules : false } ;
373
385
Some ( ( feature, level) )
374
386
}
375
- ( None , _) => {
376
- sess. emit_err ( session_diagnostics:: MissingFeature { span : attr. span } ) ;
377
- None
378
- }
379
- _ => {
380
- sess. emit_err ( session_diagnostics:: MissingSince { span : attr. span } ) ;
381
- None
382
- }
387
+ ( Err ( ErrorGuaranteed { .. } ) , _) | ( _, Err ( ErrorGuaranteed { .. } ) ) => None ,
383
388
}
384
389
}
385
390
@@ -451,12 +456,19 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
451
456
}
452
457
}
453
458
454
- match ( feature, reason, issue) {
455
- ( Some ( feature) , reason, Some ( _) ) => {
456
- if !rustc_lexer:: is_ident ( feature. as_str ( ) ) {
457
- sess. emit_err ( session_diagnostics:: NonIdentFeature { span : attr. span } ) ;
458
- return None ;
459
- }
459
+ let feature = match feature {
460
+ Some ( feature) if rustc_lexer:: is_ident ( feature. as_str ( ) ) => Ok ( feature) ,
461
+ Some ( _bad_feature) => {
462
+ Err ( sess. emit_err ( session_diagnostics:: NonIdentFeature { span : attr. span } ) )
463
+ }
464
+ None => Err ( sess. emit_err ( session_diagnostics:: MissingFeature { span : attr. span } ) ) ,
465
+ } ;
466
+
467
+ let issue =
468
+ issue. ok_or_else ( || sess. emit_err ( session_diagnostics:: MissingIssue { span : attr. span } ) ) ;
469
+
470
+ match ( feature, issue) {
471
+ ( Ok ( feature) , Ok ( _) ) => {
460
472
let level = StabilityLevel :: Unstable {
461
473
reason : UnstableReason :: from_opt_reason ( reason) ,
462
474
issue : issue_num,
@@ -465,14 +477,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
465
477
} ;
466
478
Some ( ( feature, level) )
467
479
}
468
- ( None , _, _) => {
469
- sess. emit_err ( session_diagnostics:: MissingFeature { span : attr. span } ) ;
470
- return None ;
471
- }
472
- _ => {
473
- sess. emit_err ( session_diagnostics:: MissingIssue { span : attr. span } ) ;
474
- return None ;
475
- }
480
+ ( Err ( ErrorGuaranteed { .. } ) , _) | ( _, Err ( ErrorGuaranteed { .. } ) ) => None ,
476
481
}
477
482
}
478
483
0 commit comments