@@ -353,28 +353,28 @@ pub fn find_body_stability(
353
353
body_stab
354
354
}
355
355
356
+ fn insert_or_error ( sess : & Session , meta : & MetaItem , item : & mut Option < Symbol > ) -> Option < ( ) > {
357
+ if item. is_some ( ) {
358
+ handle_errors (
359
+ & sess. parse_sess ,
360
+ meta. span ,
361
+ AttrError :: MultipleItem ( pprust:: path_to_string ( & meta. path ) ) ,
362
+ ) ;
363
+ None
364
+ } else if let Some ( v) = meta. value_str ( ) {
365
+ * item = Some ( v) ;
366
+ Some ( ( ) )
367
+ } else {
368
+ sess. emit_err ( session_diagnostics:: IncorrectMetaItem { span : meta. span } ) ;
369
+ None
370
+ }
371
+ }
372
+
356
373
/// Read the content of a `stable`/`rustc_const_stable` attribute, and return the feature name and
357
374
/// its stability information.
358
375
fn parse_stability ( sess : & Session , attr : & Attribute ) -> Option < ( Symbol , StabilityLevel ) > {
359
376
let meta = attr. meta ( ) ?;
360
377
let MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } = meta else { return None } ;
361
- let insert_or_error = |meta : & MetaItem , item : & mut Option < Symbol > | {
362
- if item. is_some ( ) {
363
- handle_errors (
364
- & sess. parse_sess ,
365
- meta. span ,
366
- AttrError :: MultipleItem ( pprust:: path_to_string ( & meta. path ) ) ,
367
- ) ;
368
- return false ;
369
- }
370
- if let Some ( v) = meta. value_str ( ) {
371
- * item = Some ( v) ;
372
- true
373
- } else {
374
- sess. emit_err ( session_diagnostics:: IncorrectMetaItem { span : meta. span } ) ;
375
- false
376
- }
377
- } ;
378
378
379
379
let mut feature = None ;
380
380
let mut since = None ;
@@ -389,16 +389,8 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
389
389
} ;
390
390
391
391
match mi. name_or_empty ( ) {
392
- sym:: feature => {
393
- if !insert_or_error ( mi, & mut feature) {
394
- return None ;
395
- }
396
- }
397
- sym:: since => {
398
- if !insert_or_error ( mi, & mut since) {
399
- return None ;
400
- }
401
- }
392
+ sym:: feature => insert_or_error ( sess, mi, & mut feature) ?,
393
+ sym:: since => insert_or_error ( sess, mi, & mut since) ?,
402
394
_ => {
403
395
handle_errors (
404
396
& sess. parse_sess ,
@@ -438,23 +430,6 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
438
430
fn parse_unstability ( sess : & Session , attr : & Attribute ) -> Option < ( Symbol , StabilityLevel ) > {
439
431
let meta = attr. meta ( ) ?;
440
432
let MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } = meta else { return None } ;
441
- let insert_or_error = |meta : & MetaItem , item : & mut Option < Symbol > | {
442
- if item. is_some ( ) {
443
- handle_errors (
444
- & sess. parse_sess ,
445
- meta. span ,
446
- AttrError :: MultipleItem ( pprust:: path_to_string ( & meta. path ) ) ,
447
- ) ;
448
- return false ;
449
- }
450
- if let Some ( v) = meta. value_str ( ) {
451
- * item = Some ( v) ;
452
- true
453
- } else {
454
- sess. emit_err ( session_diagnostics:: IncorrectMetaItem { span : meta. span } ) ;
455
- false
456
- }
457
- } ;
458
433
459
434
let mut feature = None ;
460
435
let mut reason = None ;
@@ -473,20 +448,10 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
473
448
} ;
474
449
475
450
match mi. name_or_empty ( ) {
476
- sym:: feature => {
477
- if !insert_or_error ( mi, & mut feature) {
478
- return None ;
479
- }
480
- }
481
- sym:: reason => {
482
- if !insert_or_error ( mi, & mut reason) {
483
- return None ;
484
- }
485
- }
451
+ sym:: feature => insert_or_error ( sess, mi, & mut feature) ?,
452
+ sym:: reason => insert_or_error ( sess, mi, & mut reason) ?,
486
453
sym:: issue => {
487
- if !insert_or_error ( mi, & mut issue) {
488
- return None ;
489
- }
454
+ insert_or_error ( sess, mi, & mut issue) ?;
490
455
491
456
// These unwraps are safe because `insert_or_error` ensures the meta item
492
457
// is a name/value pair string literal.
@@ -515,11 +480,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
515
480
}
516
481
is_soft = true ;
517
482
}
518
- sym:: implied_by => {
519
- if !insert_or_error ( mi, & mut implied_by) {
520
- return None ;
521
- }
522
- }
483
+ sym:: implied_by => insert_or_error ( sess, mi, & mut implied_by) ?,
523
484
_ => {
524
485
handle_errors (
525
486
& sess. parse_sess ,
0 commit comments