@@ -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, join_path_idents} ;
8+ use rustc_ast:: { self as ast, GenericParamKind , HasNodeId , attr, join_path_idents} ;
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;
@@ -473,39 +476,19 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
473476}
474477
475478fn should_panic ( cx : & ExtCtxt < ' _ > , i : & ast:: Item ) -> ShouldPanic {
476- match attr:: find_by_name ( & i. attrs , sym:: should_panic) {
477- Some ( attr) => {
478- match attr. meta_item_list ( ) {
479- // Handle #[should_panic(expected = "foo")]
480- Some ( list) => {
481- let msg = list
482- . iter ( )
483- . find ( |mi| mi. has_name ( sym:: expected) )
484- . and_then ( |mi| mi. meta_item ( ) )
485- . and_then ( |mi| mi. value_str ( ) ) ;
486- if list. len ( ) != 1 || msg. is_none ( ) {
487- cx. dcx ( )
488- . struct_span_warn (
489- attr. span ,
490- "argument must be of the form: \
491- `expected = \" error message\" `",
492- )
493- . with_note (
494- "errors in this attribute were erroneously \
495- allowed and will become a hard error in a \
496- future release",
497- )
498- . emit ( ) ;
499- ShouldPanic :: Yes ( None )
500- } else {
501- ShouldPanic :: Yes ( msg)
502- }
503- }
504- // Handle #[should_panic] and #[should_panic = "expected"]
505- None => ShouldPanic :: Yes ( attr. value_str ( ) ) ,
506- }
507- }
508- None => ShouldPanic :: No ,
479+ if let Some ( Attribute :: Parsed ( AttributeKind :: ShouldPanic { reason, .. } ) ) =
480+ AttributeParser :: parse_limited (
481+ cx. sess ,
482+ & i. attrs ,
483+ sym:: should_panic,
484+ i. span ,
485+ i. node_id ( ) ,
486+ None ,
487+ )
488+ {
489+ ShouldPanic :: Yes ( reason)
490+ } else {
491+ ShouldPanic :: No
509492 }
510493}
511494
0 commit comments