@@ -5,10 +5,13 @@ use std::assert_matches::assert_matches;
55use std:: iter;
66
77use rustc_ast:: ptr:: P ;
8- use rustc_ast:: { self as ast, GenericParamKind , attr} ;
8+ use rustc_ast:: { self as ast, GenericParamKind , HasNodeId , attr} ;
99use rustc_ast_pretty:: pprust;
10+ use rustc_attr_data_structures:: AttributeKind ;
11+ use rustc_attr_parsing:: AttributeParser ;
1012use rustc_errors:: { Applicability , Diag , Level } ;
1113use rustc_expand:: base:: * ;
14+ use rustc_hir:: Attribute ;
1215use rustc_span:: { ErrorGuaranteed , FileNameDisplayPreference , Ident , Span , Symbol , sym} ;
1316use thin_vec:: { ThinVec , thin_vec} ;
1417use tracing:: debug;
@@ -478,39 +481,12 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
478481}
479482
480483fn 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 ( cx. sess , & i. attrs , sym:: should_panic, i. span , i. node_id ( ) )
486+ {
487+ ShouldPanic :: Yes ( reason)
488+ } else {
489+ ShouldPanic :: No
514490 }
515491}
516492
0 commit comments