@@ -7,7 +7,7 @@ use crate::parse::ParseSess;
77use errors:: { Applicability , Handler } ;
88use syntax_pos:: { symbol:: Symbol , Span } ;
99
10- use super :: { list_contains_name , mark_used, MetaItemKind } ;
10+ use super :: { mark_used, MetaItemKind } ;
1111
1212enum AttrError {
1313 MultipleItem ( Name ) ,
@@ -79,40 +79,26 @@ pub enum UnwindAttr {
7979
8080/// Determine what `#[unwind]` attribute is present in `attrs`, if any.
8181pub fn find_unwind_attr ( diagnostic : Option < & Handler > , attrs : & [ Attribute ] ) -> Option < UnwindAttr > {
82- let syntax_error = |attr : & Attribute | {
83- mark_used ( attr) ;
84- diagnostic. map ( |d| {
85- span_err ! ( d, attr. span, E0633 , "malformed `#[unwind]` attribute" ) ;
86- } ) ;
87- None
88- } ;
89-
9082 attrs. iter ( ) . fold ( None , |ia, attr| {
91- if attr. path != "unwind" {
92- return ia;
93- }
94- let meta = match attr. meta ( ) {
95- Some ( meta) => meta. node ,
96- None => return ia,
97- } ;
98- match meta {
99- MetaItemKind :: Word => {
100- syntax_error ( attr)
101- }
102- MetaItemKind :: List ( ref items) => {
103- mark_used ( attr) ;
104- if items. len ( ) != 1 {
105- syntax_error ( attr)
106- } else if list_contains_name ( & items[ ..] , "allowed" ) {
107- Some ( UnwindAttr :: Allowed )
108- } else if list_contains_name ( & items[ ..] , "aborts" ) {
109- Some ( UnwindAttr :: Aborts )
110- } else {
111- syntax_error ( attr)
83+ if attr. check_name ( "unwind" ) {
84+ if let Some ( meta) = attr. meta ( ) {
85+ if let MetaItemKind :: List ( items) = meta. node {
86+ if items. len ( ) == 1 {
87+ if items[ 0 ] . check_name ( "allowed" ) {
88+ return Some ( UnwindAttr :: Allowed ) ;
89+ } else if items[ 0 ] . check_name ( "aborts" ) {
90+ return Some ( UnwindAttr :: Aborts ) ;
91+ }
92+ }
93+
94+ diagnostic. map ( |d| {
95+ span_err ! ( d, attr. span, E0633 , "malformed `#[unwind]` attribute" ) ;
96+ } ) ;
11297 }
11398 }
114- _ => ia,
11599 }
100+
101+ ia
116102 } )
117103}
118104
0 commit comments