@@ -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, join_path_idents} ;
8
+ use rustc_ast:: { self as ast, GenericParamKind , HasNodeId , attr, join_path_idents} ;
9
9
use rustc_ast_pretty:: pprust;
10
+ use rustc_attr_parsing:: AttributeParser ;
10
11
use rustc_errors:: { Applicability , Diag , Level } ;
11
12
use rustc_expand:: base:: * ;
13
+ use rustc_hir:: Attribute ;
14
+ use rustc_hir:: attrs:: AttributeKind ;
12
15
use rustc_span:: { ErrorGuaranteed , FileNameDisplayPreference , Ident , Span , Symbol , sym} ;
13
16
use thin_vec:: { ThinVec , thin_vec} ;
14
17
use tracing:: debug;
@@ -473,39 +476,19 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
473
476
}
474
477
475
478
fn 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
509
492
}
510
493
}
511
494
0 commit comments