@@ -19,9 +19,8 @@ use ptr::P;
19
19
/// A parser that can parse attributes.
20
20
pub trait ParserAttr {
21
21
fn parse_outer_attributes ( & mut self ) -> Vec < ast:: Attribute > ;
22
+ fn parse_inner_attributes ( & mut self ) -> Vec < ast:: Attribute > ;
22
23
fn parse_attribute ( & mut self , permit_inner : bool ) -> ast:: Attribute ;
23
- fn parse_inner_attrs_and_next ( & mut self )
24
- -> ( Vec < ast:: Attribute > , Vec < ast:: Attribute > ) ;
25
24
fn parse_meta_item ( & mut self ) -> P < ast:: MetaItem > ;
26
25
fn parse_meta_seq ( & mut self ) -> Vec < P < ast:: MetaItem > > ;
27
26
fn parse_optional_meta ( & mut self ) -> Vec < P < ast:: MetaItem > > ;
@@ -118,45 +117,40 @@ impl<'a> ParserAttr for Parser<'a> {
118
117
119
118
/// Parse attributes that appear after the opening of an item. These should
120
119
/// be preceded by an exclamation mark, but we accept and warn about one
121
- /// terminated by a semicolon. In addition to a vector of inner attributes,
122
- /// this function also returns a vector that may contain the first outer
123
- /// attribute of the next item (since we can't know whether the attribute
124
- /// is an inner attribute of the containing item or an outer attribute of
125
- /// the first contained item until we see the semi).
126
-
127
- /// matches inner_attrs* outer_attr?
128
- /// you can make the 'next' field an Option, but the result is going to be
129
- /// more useful as a vector.
130
- fn parse_inner_attrs_and_next ( & mut self )
131
- -> ( Vec < ast:: Attribute > , Vec < ast:: Attribute > ) {
132
- let mut inner_attrs: Vec < ast:: Attribute > = Vec :: new ( ) ;
133
- let mut next_outer_attrs: Vec < ast:: Attribute > = Vec :: new ( ) ;
120
+ /// terminated by a semicolon.
121
+
122
+ /// matches inner_attrs*
123
+ fn parse_inner_attributes ( & mut self ) -> Vec < ast:: Attribute > {
124
+ let mut attrs: Vec < ast:: Attribute > = vec ! [ ] ;
134
125
loop {
135
- let attr = match self . token {
126
+ match self . token {
136
127
token:: Pound => {
137
- self . parse_attribute ( true )
128
+ // Don't even try to parse if it's not an inner attribute.
129
+ if !self . look_ahead ( 1 , |t| t == & token:: Not ) {
130
+ break ;
131
+ }
132
+
133
+ let attr = self . parse_attribute ( true ) ;
134
+ assert ! ( attr. node. style == ast:: AttrInner ) ;
135
+ attrs. push ( attr) ;
138
136
}
139
137
token:: DocComment ( s) => {
140
138
// we need to get the position of this token before we bump.
141
139
let Span { lo, hi, .. } = self . span ;
142
- self . bump ( ) ;
143
- attr:: mk_sugared_doc_attr ( attr:: mk_attr_id ( ) ,
144
- self . id_to_interned_str ( s. ident ( ) ) ,
145
- lo,
146
- hi)
147
- }
148
- _ => {
149
- break ;
140
+ let attr = attr:: mk_sugared_doc_attr ( attr:: mk_attr_id ( ) ,
141
+ self . id_to_interned_str ( s. ident ( ) ) ,
142
+ lo, hi) ;
143
+ if attr. node . style == ast:: AttrInner {
144
+ attrs. push ( attr) ;
145
+ self . bump ( ) ;
146
+ } else {
147
+ break ;
148
+ }
150
149
}
151
- } ;
152
- if attr. node . style == ast:: AttrInner {
153
- inner_attrs. push ( attr) ;
154
- } else {
155
- next_outer_attrs. push ( attr) ;
156
- break ;
150
+ _ => break
157
151
}
158
152
}
159
- ( inner_attrs , next_outer_attrs )
153
+ attrs
160
154
}
161
155
162
156
/// matches meta_item = IDENT
0 commit comments