@@ -257,7 +257,8 @@ fn print_item(&ps s, &@ast::item item) {
257
257
hardbreak ( s. s ) ;
258
258
maybe_print_comment ( s, item. span . lo ) ;
259
259
alt ( item. node ) {
260
- case ( ast:: item_const ( ?id, ?ty, ?expr, _, _, _) ) {
260
+ case ( ast:: item_const ( ?id, ?ty, ?expr, ?attrs, _, _) ) {
261
+ print_outer_attributes ( s, attrs) ;
261
262
head ( s, "const" ) ;
262
263
print_type ( s, * ty) ;
263
264
space ( s. s ) ;
@@ -268,19 +269,22 @@ fn print_item(&ps s, &@ast::item item) {
268
269
word ( s. s , ";" ) ;
269
270
end ( s) ; // end the outer cbox
270
271
}
271
- case ( ast:: item_fn ( ?name, ?_fn, ?typarams, _, _, _) ) {
272
+ case ( ast:: item_fn ( ?name, ?_fn, ?typarams, ?attrs, _, _) ) {
273
+ print_outer_attributes ( s, attrs) ;
272
274
print_fn ( s, _fn. decl , _fn. proto , name, typarams) ;
273
275
word ( s. s , " " ) ;
274
276
print_block ( s, _fn. body ) ;
275
277
}
276
- case ( ast:: item_mod ( ?id, ?_mod, _, _) ) {
278
+ case ( ast:: item_mod ( ?id, ?_mod, ?attrs, _) ) {
279
+ print_outer_attributes ( s, attrs) ;
277
280
head ( s, "mod" ) ;
278
281
word_nbsp ( s, id) ;
279
282
bopen ( s) ;
280
283
for ( @ast:: item itm in _mod. items) { print_item ( s, itm) ; }
281
284
bclose ( s, item. span ) ;
282
285
}
283
- case ( ast:: item_native_mod ( ?id, ?nmod, _, _) ) {
286
+ case ( ast:: item_native_mod ( ?id, ?nmod, ?attrs, _) ) {
287
+ print_outer_attributes ( s, attrs) ;
284
288
head ( s, "native" ) ;
285
289
alt ( nmod. abi ) {
286
290
case ( ast:: native_abi_rust) { word_nbsp ( s, "\" rust\" " ) ; }
@@ -317,7 +321,8 @@ fn print_item(&ps s, &@ast::item item) {
317
321
}
318
322
bclose ( s, item. span ) ;
319
323
}
320
- case ( ast:: item_ty ( ?id, ?ty, ?params, _, _, _) ) {
324
+ case ( ast:: item_ty ( ?id, ?ty, ?params, ?attrs, _, _) ) {
325
+ print_outer_attributes ( s, attrs) ;
321
326
ibox ( s, indent_unit) ;
322
327
ibox ( s, 0 u) ;
323
328
word_nbsp ( s, "type" ) ;
@@ -331,7 +336,8 @@ fn print_item(&ps s, &@ast::item item) {
331
336
end ( s) ; // end the outer ibox
332
337
break_offset ( s. s , 0 u, 0 ) ;
333
338
}
334
- case ( ast:: item_tag ( ?id, ?variants, ?params, _, _, _) ) {
339
+ case ( ast:: item_tag ( ?id, ?variants, ?params, ?attrs, _, _) ) {
340
+ print_outer_attributes ( s, attrs) ;
335
341
head ( s, "tag" ) ;
336
342
word ( s. s , id) ;
337
343
print_type_params ( s, params) ;
@@ -354,7 +360,8 @@ fn print_item(&ps s, &@ast::item item) {
354
360
}
355
361
bclose ( s, item. span ) ;
356
362
}
357
- case ( ast:: item_obj ( ?id, ?_obj, ?params, _, _, _) ) {
363
+ case ( ast:: item_obj ( ?id, ?_obj, ?params, ?attrs, _, _) ) {
364
+ print_outer_attributes ( s, attrs) ;
358
365
head ( s, "obj" ) ;
359
366
word ( s. s , id) ;
360
367
print_type_params ( s, params) ;
@@ -401,6 +408,30 @@ fn print_item(&ps s, &@ast::item item) {
401
408
}
402
409
}
403
410
411
+ fn print_outer_attributes ( & ps s, vec[ ast:: attribute ] attrs ) {
412
+ auto count = 0 ;
413
+ for ( ast:: attribute attr in attrs) {
414
+ alt ( attr. node . style ) {
415
+ case ( ast:: attr_outer) {
416
+ print_attribute ( s, attr) ;
417
+ count += 1 ;
418
+ }
419
+ case ( _) { /* fallthrough */ }
420
+ }
421
+ }
422
+ if ( count > 0 ) {
423
+ hardbreak ( s. s ) ;
424
+ }
425
+ }
426
+
427
+ fn print_attribute ( & ps s, & ast:: attribute attr) {
428
+ hardbreak ( s. s ) ;
429
+ maybe_print_comment ( s, attr. span . lo ) ;
430
+ word ( s. s , "#[" ) ;
431
+ print_meta_item ( s, @attr. node . value ) ;
432
+ word ( s. s , "]" ) ;
433
+ }
434
+
404
435
fn print_stmt ( & ps s, & ast:: stmt st) {
405
436
maybe_print_comment ( s, st. span . lo ) ;
406
437
alt ( st. node ) {
@@ -987,6 +1018,14 @@ fn print_type_params(&ps s, &vec[ast::ty_param] params) {
987
1018
}
988
1019
}
989
1020
1021
+ fn print_meta_item ( & ps s, & @ast:: meta_item item) {
1022
+ ibox ( s, indent_unit) ;
1023
+ word_space ( s, item. node . key ) ;
1024
+ word_space ( s, "=" ) ;
1025
+ print_string ( s, item. node . value ) ;
1026
+ end ( s) ;
1027
+ }
1028
+
990
1029
fn print_view_item ( & ps s, & @ast:: view_item item) {
991
1030
hardbreak ( s. s ) ;
992
1031
maybe_print_comment ( s, item. span . lo ) ;
@@ -996,14 +1035,7 @@ fn print_view_item(&ps s, &@ast::view_item item) {
996
1035
word ( s. s , id) ;
997
1036
if ( vec:: len ( mta) > 0 u) {
998
1037
popen ( s) ;
999
- fn print_meta ( & ps s, & @ast:: meta_item item) {
1000
- ibox ( s, indent_unit) ;
1001
- word_space ( s, item. node . key ) ;
1002
- word_space ( s, "=" ) ;
1003
- print_string ( s, item. node . value ) ;
1004
- end ( s) ;
1005
- }
1006
- commasep ( s, consistent, mta, print_meta) ;
1038
+ commasep ( s, consistent, mta, print_meta_item) ;
1007
1039
pclose ( s) ;
1008
1040
}
1009
1041
}
0 commit comments