@@ -7,7 +7,7 @@ use crate::parse::ParseSess;
7
7
use errors:: { Applicability , Handler } ;
8
8
use syntax_pos:: { symbol:: Symbol , Span } ;
9
9
10
- use super :: { list_contains_name , mark_used, MetaItemKind } ;
10
+ use super :: { mark_used, MetaItemKind } ;
11
11
12
12
enum AttrError {
13
13
MultipleItem ( Name ) ,
@@ -79,40 +79,26 @@ pub enum UnwindAttr {
79
79
80
80
/// Determine what `#[unwind]` attribute is present in `attrs`, if any.
81
81
pub 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
-
90
82
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
+ } ) ;
112
97
}
113
98
}
114
- _ => ia,
115
99
}
100
+
101
+ ia
116
102
} )
117
103
}
118
104
0 commit comments