@@ -5,10 +5,13 @@ use std::assert_matches::assert_matches;
5
5
use std:: iter;
6
6
7
7
use rustc_ast:: ptr:: P ;
8
- use rustc_ast:: { self as ast, GenericParamKind , attr} ;
8
+ use rustc_ast:: { self as ast, GenericParamKind , HasNodeId , attr} ;
9
9
use rustc_ast_pretty:: pprust;
10
+ use rustc_attr_data_structures:: AttributeKind ;
11
+ use rustc_attr_parsing:: AttributeParser ;
10
12
use rustc_errors:: { Applicability , Diag , Level } ;
11
13
use rustc_expand:: base:: * ;
14
+ use rustc_hir:: Attribute ;
12
15
use rustc_span:: { ErrorGuaranteed , FileNameDisplayPreference , Ident , Span , Symbol , sym} ;
13
16
use thin_vec:: { ThinVec , thin_vec} ;
14
17
use tracing:: debug;
@@ -478,39 +481,19 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
478
481
}
479
482
480
483
fn should_panic ( cx : & ExtCtxt < ' _ > , i : & ast:: Item ) -> ShouldPanic {
481
- match attr:: find_by_name ( & i. attrs , sym:: should_panic) {
482
- Some ( attr) => {
483
- match attr. meta_item_list ( ) {
484
- // Handle #[should_panic(expected = "foo")]
485
- Some ( list) => {
486
- let msg = list
487
- . iter ( )
488
- . find ( |mi| mi. has_name ( sym:: expected) )
489
- . and_then ( |mi| mi. meta_item ( ) )
490
- . and_then ( |mi| mi. value_str ( ) ) ;
491
- if list. len ( ) != 1 || msg. is_none ( ) {
492
- cx. dcx ( )
493
- . struct_span_warn (
494
- attr. span ,
495
- "argument must be of the form: \
496
- `expected = \" error message\" `",
497
- )
498
- . with_note (
499
- "errors in this attribute were erroneously \
500
- allowed and will become a hard error in a \
501
- future release",
502
- )
503
- . emit ( ) ;
504
- ShouldPanic :: Yes ( None )
505
- } else {
506
- ShouldPanic :: Yes ( msg)
507
- }
508
- }
509
- // Handle #[should_panic] and #[should_panic = "expected"]
510
- None => ShouldPanic :: Yes ( attr. value_str ( ) ) ,
511
- }
512
- }
513
- None => ShouldPanic :: No ,
484
+ if let Some ( Attribute :: Parsed ( AttributeKind :: ShouldPanic { reason, .. } ) ) =
485
+ AttributeParser :: parse_limited (
486
+ cx. sess ,
487
+ & i. attrs ,
488
+ sym:: should_panic,
489
+ i. span ,
490
+ i. node_id ( ) ,
491
+ None ,
492
+ )
493
+ {
494
+ ShouldPanic :: Yes ( reason)
495
+ } else {
496
+ ShouldPanic :: No
514
497
}
515
498
}
516
499
0 commit comments