Skip to content

Commit b727d07

Browse files
committed
rustc: Pretty print module inner attributes
Issue #487
1 parent 43cbbab commit b727d07

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/comp/pretty/pprust.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ fn print_type(&ps s, &ast::ty ty) {
264264
fn print_item(&ps s, &@ast::item item) {
265265
hardbreak(s.s);
266266
maybe_print_comment(s, item.span.lo);
267+
print_outer_attributes(s, item.attrs);
267268
alt (item.node) {
268269
case (ast::item_const(?ty, ?expr)) {
269-
print_outer_attributes(s, item.attrs);
270270
head(s, "const");
271271
print_type(s, *ty);
272272
space(s.s);
@@ -280,21 +280,19 @@ fn print_item(&ps s, &@ast::item item) {
280280

281281
}
282282
case (ast::item_fn(?_fn, ?typarams)) {
283-
print_outer_attributes(s, item.attrs);
284283
print_fn(s, _fn.decl, _fn.proto, item.ident, typarams);
285284
word(s.s, " ");
286285
print_block(s, _fn.body);
287286
}
288287
case (ast::item_mod(?_mod)) {
289-
print_outer_attributes(s, item.attrs);
290288
head(s, "mod");
291289
word_nbsp(s, item.ident);
292290
bopen(s);
291+
print_inner_attributes(s, item.attrs);
293292
for (@ast::item itm in _mod.items) { print_item(s, itm); }
294293
bclose(s, item.span);
295294
}
296295
case (ast::item_native_mod(?nmod)) {
297-
print_outer_attributes(s, item.attrs);
298296
head(s, "native");
299297
alt (nmod.abi) {
300298
case (ast::native_abi_rust) { word_nbsp(s, "\"rust\""); }
@@ -338,7 +336,6 @@ fn print_item(&ps s, &@ast::item item) {
338336
bclose(s, item.span);
339337
}
340338
case (ast::item_ty(?ty, ?params)) {
341-
print_outer_attributes(s, item.attrs);
342339
ibox(s, indent_unit);
343340
ibox(s, 0u);
344341
word_nbsp(s, "type");
@@ -355,7 +352,6 @@ fn print_item(&ps s, &@ast::item item) {
355352
break_offset(s.s, 0u, 0);
356353
}
357354
case (ast::item_tag(?variants, ?params)) {
358-
print_outer_attributes(s, item.attrs);
359355
head(s, "tag");
360356
word(s.s, item.ident);
361357
print_type_params(s, params);
@@ -379,7 +375,6 @@ fn print_item(&ps s, &@ast::item item) {
379375
bclose(s, item.span);
380376
}
381377
case (ast::item_obj(?_obj, ?params, _)) {
382-
print_outer_attributes(s, item.attrs);
383378
head(s, "obj");
384379
word(s.s, item.ident);
385380
print_type_params(s, params);
@@ -438,6 +433,21 @@ fn print_outer_attributes(&ps s, vec[ast::attribute] attrs) {
438433
if (count > 0) { hardbreak(s.s); }
439434
}
440435

436+
fn print_inner_attributes(&ps s, vec[ast::attribute] attrs) {
437+
auto count = 0;
438+
for (ast::attribute attr in attrs) {
439+
alt (attr.node.style) {
440+
case (ast::attr_inner) {
441+
print_attribute(s, attr);
442+
word(s.s, ";");
443+
count += 1;
444+
}
445+
case (_) { /* fallthrough */ }
446+
}
447+
}
448+
if (count > 0) { hardbreak(s.s); }
449+
}
450+
441451
fn print_attribute(&ps s, &ast::attribute attr) {
442452
hardbreak(s.s);
443453
maybe_print_comment(s, attr.span.lo);

0 commit comments

Comments
 (0)