Skip to content

Commit 92ed73d

Browse files
committed
rustc: Add pretty printing support for the address-of operator. Un-XFAIL-pretty simple-regions.rs.
1 parent c40bfec commit 92ed73d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/rustc/syntax/print/pprust.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ fn print_native_mod(s: ps, nmod: ast::native_mod, attrs: [ast::attribute]) {
313313
for item: @ast::native_item in nmod.items { print_native_item(s, item); }
314314
}
315315

316+
fn print_region(s: ps, region: ast::region) {
317+
alt region {
318+
ast::re_inferred { /* no-op */ }
319+
ast::re_named(name) { word(s.s, name); word(s.s, "."); }
320+
ast::re_self { word(s.s, "self"); word(s.s, "."); }
321+
}
322+
}
323+
316324
fn print_type(s: ps, &&ty: @ast::ty) {
317325
maybe_print_comment(s, ty.span.lo);
318326
ibox(s, 0u);
@@ -332,7 +340,11 @@ fn print_type(s: ps, &&ty: @ast::ty) {
332340
word(s.s, "]");
333341
}
334342
ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); }
335-
ast::ty_rptr(region, mt) { fail "TODO"; }
343+
ast::ty_rptr(region, mt) {
344+
word(s.s, "&");
345+
print_region(s, region);
346+
print_mt(s, mt);
347+
}
336348
ast::ty_rec(fields) {
337349
word(s.s, "{");
338350
fn print_field(s: ps, f: ast::ty_field) {
@@ -878,6 +890,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
878890
print_op_maybe_parens(s, expr, parse::parser::unop_prec);
879891
}
880892
ast::expr_addr_of(m, expr) {
893+
word(s.s, "&");
881894
print_mutability(s, m);
882895
print_expr(s, expr);
883896
}

src/test/run-pass/simple-regions.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// xfail-pretty
2-
31
fn main() {
4-
unsafe {
5-
let x : int = 3;
6-
let y : &mut int = &mut x;
2+
unsafe{
3+
let x: int = 3;
4+
let y: &mutable int = &mutable x;
75
*y = 5;
8-
log(debug, *y);
6+
log (debug, *y);
97
}
108
}
119

0 commit comments

Comments
 (0)