@@ -26,7 +26,8 @@ pub use self::Code::*;
26
26
use front:: map:: { self , Node } ;
27
27
use syntax:: abi;
28
28
use rustc_front:: hir:: { Block , FnDecl } ;
29
- use syntax:: ast:: { Name , NodeId } ;
29
+ use syntax:: ast:: { Attribute , Name , NodeId } ;
30
+ use syntax:: attr:: ThinAttributesExt ;
30
31
use rustc_front:: hir as ast;
31
32
use syntax:: codemap:: Span ;
32
33
use rustc_front:: intravisit:: FnKind ;
@@ -116,7 +117,8 @@ struct ItemFnParts<'a> {
116
117
generics : & ' a ast:: Generics ,
117
118
body : & ' a Block ,
118
119
id : NodeId ,
119
- span : Span
120
+ span : Span ,
121
+ attrs : & ' a [ Attribute ] ,
120
122
}
121
123
122
124
/// These are all the components one can extract from a closure expr
@@ -125,12 +127,13 @@ struct ClosureParts<'a> {
125
127
decl : & ' a FnDecl ,
126
128
body : & ' a Block ,
127
129
id : NodeId ,
128
- span : Span
130
+ span : Span ,
131
+ attrs : & ' a [ Attribute ] ,
129
132
}
130
133
131
134
impl < ' a > ClosureParts < ' a > {
132
- fn new ( d : & ' a FnDecl , b : & ' a Block , id : NodeId , s : Span ) -> ClosureParts < ' a > {
133
- ClosureParts { decl : d, body : b, id : id, span : s }
135
+ fn new ( d : & ' a FnDecl , b : & ' a Block , id : NodeId , s : Span , attrs : & ' a [ Attribute ] ) -> Self {
136
+ ClosureParts { decl : d, body : b, id : id, span : s, attrs : attrs }
134
137
}
135
138
}
136
139
@@ -165,37 +168,37 @@ impl<'a> FnLikeNode<'a> {
165
168
166
169
pub fn body ( self ) -> & ' a Block {
167
170
self . handle ( |i : ItemFnParts < ' a > | & * i. body ,
168
- |_, _, _: & ' a ast:: MethodSig , _, body : & ' a ast:: Block , _| body,
171
+ |_, _, _: & ' a ast:: MethodSig , _, body : & ' a ast:: Block , _, _ | body,
169
172
|c : ClosureParts < ' a > | c. body )
170
173
}
171
174
172
175
pub fn decl ( self ) -> & ' a FnDecl {
173
176
self . handle ( |i : ItemFnParts < ' a > | & * i. decl ,
174
- |_, _, sig : & ' a ast:: MethodSig , _, _, _| & sig. decl ,
177
+ |_, _, sig : & ' a ast:: MethodSig , _, _, _, _ | & sig. decl ,
175
178
|c : ClosureParts < ' a > | c. decl )
176
179
}
177
180
178
181
pub fn span ( self ) -> Span {
179
182
self . handle ( |i : ItemFnParts | i. span ,
180
- |_, _, _: & ' a ast:: MethodSig , _, _, span| span,
183
+ |_, _, _: & ' a ast:: MethodSig , _, _, span, _ | span,
181
184
|c : ClosureParts | c. span )
182
185
}
183
186
184
187
pub fn id ( self ) -> NodeId {
185
188
self . handle ( |i : ItemFnParts | i. id ,
186
- |id, _, _: & ' a ast:: MethodSig , _, _, _| id,
189
+ |id, _, _: & ' a ast:: MethodSig , _, _, _, _ | id,
187
190
|c : ClosureParts | c. id )
188
191
}
189
192
190
193
pub fn kind ( self ) -> FnKind < ' a > {
191
194
let item = |p : ItemFnParts < ' a > | -> FnKind < ' a > {
192
- FnKind :: ItemFn ( p. name , p. generics , p. unsafety , p. constness , p. abi , p. vis )
195
+ FnKind :: ItemFn ( p. name , p. generics , p. unsafety , p. constness , p. abi , p. vis , p . attrs )
193
196
} ;
194
- let closure = |_ : ClosureParts | {
195
- FnKind :: Closure
197
+ let closure = |c : ClosureParts < ' a > | {
198
+ FnKind :: Closure ( c . attrs )
196
199
} ;
197
- let method = |_, name : Name , sig : & ' a ast:: MethodSig , vis, _, _| {
198
- FnKind :: Method ( name, sig, vis)
200
+ let method = |_, name : Name , sig : & ' a ast:: MethodSig , vis, _, _, attrs | {
201
+ FnKind :: Method ( name, sig, vis, attrs )
199
202
} ;
200
203
self . handle ( item, method, closure)
201
204
}
@@ -207,7 +210,8 @@ impl<'a> FnLikeNode<'a> {
207
210
& ' a ast:: MethodSig ,
208
211
Option < ast:: Visibility > ,
209
212
& ' a ast:: Block ,
210
- Span )
213
+ Span ,
214
+ & ' a [ Attribute ] )
211
215
-> A ,
212
216
C : FnOnce ( ClosureParts < ' a > ) -> A ,
213
217
{
@@ -224,20 +228,21 @@ impl<'a> FnLikeNode<'a> {
224
228
abi : abi,
225
229
vis : i. vis ,
226
230
constness : constness,
227
- span : i. span
231
+ span : i. span ,
232
+ attrs : & i. attrs ,
228
233
} ) ,
229
234
_ => panic ! ( "item FnLikeNode that is not fn-like" ) ,
230
235
} ,
231
236
map:: NodeTraitItem ( ti) => match ti. node {
232
237
ast:: MethodTraitItem ( ref sig, Some ( ref body) ) => {
233
- method ( ti. id , ti. name , sig, None , body, ti. span )
238
+ method ( ti. id , ti. name , sig, None , body, ti. span , & ti . attrs )
234
239
}
235
240
_ => panic ! ( "trait method FnLikeNode that is not fn-like" ) ,
236
241
} ,
237
242
map:: NodeImplItem ( ii) => {
238
243
match ii. node {
239
244
ast:: ImplItemKind :: Method ( ref sig, ref body) => {
240
- method ( ii. id , ii. name , sig, Some ( ii. vis ) , body, ii. span )
245
+ method ( ii. id , ii. name , sig, Some ( ii. vis ) , body, ii. span , & ii . attrs )
241
246
}
242
247
_ => {
243
248
panic ! ( "impl method FnLikeNode that is not fn-like" )
@@ -246,7 +251,11 @@ impl<'a> FnLikeNode<'a> {
246
251
}
247
252
map:: NodeExpr ( e) => match e. node {
248
253
ast:: ExprClosure ( _, ref decl, ref block) =>
249
- closure ( ClosureParts :: new ( & decl, & block, e. id , e. span ) ) ,
254
+ closure ( ClosureParts :: new ( & decl,
255
+ & block,
256
+ e. id ,
257
+ e. span ,
258
+ e. attrs . as_attr_slice ( ) ) ) ,
250
259
_ => panic ! ( "expr FnLikeNode that is not fn-like" ) ,
251
260
} ,
252
261
_ => panic ! ( "other FnLikeNode that is not fn-like" ) ,
0 commit comments