Skip to content

Commit 50b1953

Browse files
committed
Pretty-print view items in mod items
For mods that aren't defined at the file level we were forgetting to print the view items so, e.g. 'mod { use std; }' would not print correctly.
1 parent 1e63d53 commit 50b1953

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/comp/pretty/pprust.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ fn print_crate(session sess, @ast::crate crate, str filename,
4141
mutable cur_lit=0u,
4242
mutable boxes=boxes,
4343
mode=mode);
44-
print_inner_attributes(s, crate.node.attrs);
45-
print_mod(s, crate.node.module);
44+
print_mod(s, crate.node.module, crate.node.attrs);
4645
eof(s.s);
4746
}
4847

@@ -186,7 +185,8 @@ fn commasep_exprs(&ps s, breaks b, vec[@ast::expr] exprs) {
186185
commasep_cmnt(s, b, exprs, print_expr, expr_span);
187186
}
188187

189-
fn print_mod(&ps s, ast::_mod _mod) {
188+
fn print_mod(&ps s, ast::_mod _mod, &vec[ast::attribute] attrs) {
189+
print_inner_attributes(s, attrs);
190190
for (@ast::view_item vitem in _mod.view_items) {
191191
print_view_item(s, vitem);
192192
}
@@ -322,8 +322,7 @@ fn print_item(&ps s, &@ast::item item) {
322322
head(s, "mod");
323323
word_nbsp(s, item.ident);
324324
bopen(s);
325-
print_inner_attributes(s, item.attrs);
326-
for (@ast::item itm in _mod.items) { print_item(s, itm); }
325+
print_mod(s, _mod, item.attrs);
327326
bclose(s, item.span);
328327
}
329328
case (ast::item_native_mod(?nmod)) {

src/test/run-pass/mod-view-items.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Test view items inside non-file-level mods
2+
3+
// This is a regression test for an issue where we were failing to
4+
// pretty-print such view items. If that happens again, this should
5+
// begin failing.
6+
7+
mod m {
8+
use std;
9+
import std::vec;
10+
fn f() -> vec[int] { vec::empty[int]() }
11+
}
12+
13+
fn main() {
14+
auto x = m::f();
15+
}

0 commit comments

Comments
 (0)