1
Fork 0

Fix bad argument type of pprust::print_type

AST types are boxed, there's no need for every caller to do the unboxing
This commit is contained in:
Marijn Haverbeke 2011-08-15 13:45:04 +02:00
parent 1570949ef1
commit a21ebb2f5e
3 changed files with 27 additions and 29 deletions

View file

@ -151,7 +151,7 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
return a value"); return a value");
fcx.ccx.tcx.sess.span_fatal(f.decl.output.span, fcx.ccx.tcx.sess.span_fatal(f.decl.output.span,
"see declared return type of '" + "see declared return type of '" +
ty_to_str(*f.decl.output) + "'"); ty_to_str(f.decl.output) + "'");
} else if (f.decl.cf == noreturn) { } else if (f.decl.cf == noreturn) {
// check that this really always fails // check that this really always fails
// Note that it's ok for i_diverge and i_return to both be true. // Note that it's ok for i_diverge and i_return to both be true.

View file

@ -90,7 +90,7 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: str,
eof(s.s); eof(s.s);
} }
fn ty_to_str(ty: &ast::ty) -> str { be to_str(ty, print_type); } fn ty_to_str(ty: &@ast::ty) -> str { be to_str(ty, print_type); }
fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); } fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); }
@ -268,9 +268,7 @@ fn print_native_mod(s: &ps, nmod: &ast::native_mod,
for item: @ast::native_item in nmod.items { print_native_item(s, item); } for item: @ast::native_item in nmod.items { print_native_item(s, item); }
} }
fn print_boxed_type(s: &ps, ty: &@ast::ty) { print_type(s, *ty); } fn print_type(s: &ps, ty: &@ast::ty) {
fn print_type(s: &ps, ty: &ast::ty) {
maybe_print_comment(s, ty.span.lo); maybe_print_comment(s, ty.span.lo);
ibox(s, 0u); ibox(s, 0u);
alt ty.node { alt ty.node {
@ -293,19 +291,19 @@ fn print_type(s: &ps, ty: &ast::ty) {
ast::maybe_mut. { word_space(s, "mutable?"); } ast::maybe_mut. { word_space(s, "mutable?"); }
ast::imm. {} ast::imm. {}
} }
print_type(s, *mt.ty); print_type(s, mt.ty);
word(s.s, "]"); word(s.s, "]");
} }
ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); } ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); }
ast::ty_task. { word(s.s, "task"); } ast::ty_task. { word(s.s, "task"); }
ast::ty_port(t) { ast::ty_port(t) {
word(s.s, "port["); word(s.s, "port[");
print_type(s, *t); print_type(s, t);
word(s.s, "]"); word(s.s, "]");
} }
ast::ty_chan(t) { ast::ty_chan(t) {
word(s.s, "chan["); word(s.s, "chan[");
print_type(s, *t); print_type(s, t);
word(s.s, "]"); word(s.s, "]");
} }
ast::ty_rec(fields) { ast::ty_rec(fields) {
@ -315,7 +313,7 @@ fn print_type(s: &ps, ty: &ast::ty) {
print_mutability(s, f.node.mt.mut); print_mutability(s, f.node.mt.mut);
word(s.s, f.node.ident); word(s.s, f.node.ident);
word_space(s, ":"); word_space(s, ":");
print_type(s, *f.node.mt.ty); print_type(s, f.node.mt.ty);
end(s); end(s);
} }
fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; } fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; }
@ -324,7 +322,7 @@ fn print_type(s: &ps, ty: &ast::ty) {
} }
ast::ty_tup(elts) { ast::ty_tup(elts) {
popen(s); popen(s);
commasep(s, inconsistent, elts, print_boxed_type); commasep(s, inconsistent, elts, print_type);
pclose(s); pclose(s);
} }
ast::ty_fn(proto, inputs, output, cf, constrs) { ast::ty_fn(proto, inputs, output, cf, constrs) {
@ -347,7 +345,7 @@ fn print_type(s: &ps, ty: &ast::ty) {
ast::ty_path(path, _) { print_path(s, path); } ast::ty_path(path, _) { print_path(s, path); }
ast::ty_type. { word(s.s, "type"); } ast::ty_type. { word(s.s, "type"); }
ast::ty_constr(t, cs) { ast::ty_constr(t, cs) {
print_type(s, *t); print_type(s, t);
space(s.s); space(s.s);
word(s.s, ast_ty_constrs_str(cs)); word(s.s, ast_ty_constrs_str(cs));
} }
@ -396,7 +394,7 @@ fn print_item(s: &ps, item: &@ast::item) {
ast::item_const(ty, expr) { ast::item_const(ty, expr) {
head(s, "const"); head(s, "const");
word_space(s, item.ident + ":"); word_space(s, item.ident + ":");
print_type(s, *ty); print_type(s, ty);
space(s.s); space(s.s);
end(s); // end the head-ibox end(s); // end the head-ibox
@ -451,7 +449,7 @@ fn print_item(s: &ps, item: &@ast::item) {
space(s.s); space(s.s);
word_space(s, "="); word_space(s, "=");
print_type(s, *ty); print_type(s, ty);
word(s.s, ";"); word(s.s, ";");
end(s); // end the outer ibox end(s); // end the outer ibox
} }
@ -469,7 +467,7 @@ fn print_item(s: &ps, item: &@ast::item) {
space(s.s); space(s.s);
if newtype { if newtype {
word_space(s, "="); word_space(s, "=");
print_type(s, *variants.(0).node.args.(0).ty); print_type(s, variants.(0).node.args.(0).ty);
word(s.s, ";"); word(s.s, ";");
end(s); end(s);
} else { } else {
@ -481,7 +479,7 @@ fn print_item(s: &ps, item: &@ast::item) {
if ivec::len(v.node.args) > 0u { if ivec::len(v.node.args) > 0u {
popen(s); popen(s);
fn print_variant_arg(s: &ps, arg: &ast::variant_arg) { fn print_variant_arg(s: &ps, arg: &ast::variant_arg) {
print_type(s, *arg.ty); print_type(s, arg.ty);
} }
commasep(s, consistent, v.node.args, print_variant_arg); commasep(s, consistent, v.node.args, print_variant_arg);
pclose(s); pclose(s);
@ -501,7 +499,7 @@ fn print_item(s: &ps, item: &@ast::item) {
ibox(s, indent_unit); ibox(s, indent_unit);
print_mutability(s, field.mut); print_mutability(s, field.mut);
word_space(s, field.ident + ":"); word_space(s, field.ident + ":");
print_type(s, *field.ty); print_type(s, field.ty);
end(s); end(s);
} }
fn get_span(f: &ast::obj_field) -> codemap::span { ret f.ty.span; } fn get_span(f: &ast::obj_field) -> codemap::span { ret f.ty.span; }
@ -526,7 +524,7 @@ fn print_item(s: &ps, item: &@ast::item) {
print_type_params(s, tps); print_type_params(s, tps);
popen(s); popen(s);
word_space(s, dt.decl.inputs.(0).ident + ":"); word_space(s, dt.decl.inputs.(0).ident + ":");
print_type(s, *dt.decl.inputs.(0).ty); print_type(s, dt.decl.inputs.(0).ty);
pclose(s); pclose(s);
space(s.s); space(s.s);
print_block(s, dt.body); print_block(s, dt.body);
@ -697,7 +695,7 @@ fn print_mac(s: &ps, m: &ast::mac) {
} }
ast::mac_embed_type(ty) { ast::mac_embed_type(ty) {
word(s.s, "#<"); word(s.s, "#<");
print_type(s, *ty); print_type(s, ty);
word(s.s, ">"); word(s.s, ">");
} }
ast::mac_embed_block(blk) { ast::mac_embed_block(blk) {
@ -803,7 +801,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
print_maybe_parens(s, expr, parse::parser::as_prec); print_maybe_parens(s, expr, parse::parser::as_prec);
space(s.s); space(s.s);
word_space(s, "as"); word_space(s, "as");
print_type(s, *ty); print_type(s, ty);
} }
ast::expr_if(test, blk, elseopt) { ast::expr_if(test, blk, elseopt) {
print_if(s, test, blk, elseopt, false); print_if(s, test, blk, elseopt, false);
@ -981,7 +979,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
word(s.s, "port"); word(s.s, "port");
alt t.node { alt t.node {
ast::ty_infer. { } ast::ty_infer. { }
_ { word(s.s, "["); print_type(s, *t); word(s.s, "]"); } _ { word(s.s, "["); print_type(s, t); word(s.s, "]"); }
} }
popen(s); popen(s);
pclose(s); pclose(s);
@ -1001,7 +999,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
ibox(s, indent_unit); ibox(s, indent_unit);
print_mutability(s, field.mut); print_mutability(s, field.mut);
word_space(s, field.ident + ":"); word_space(s, field.ident + ":");
print_type(s, *field.ty); print_type(s, field.ty);
space(s.s); space(s.s);
word_space(s, "="); word_space(s, "=");
print_expr(s, field.expr); print_expr(s, field.expr);
@ -1055,7 +1053,7 @@ fn print_local_decl(s: &ps, loc: &@ast::local) {
print_pat(s, loc.node.pat); print_pat(s, loc.node.pat);
alt loc.node.ty.node { alt loc.node.ty.node {
ast::ty_infer. { } ast::ty_infer. { }
_ { word_space(s, ":"); print_type(s, *loc.node.ty); } _ { word_space(s, ":"); print_type(s, loc.node.ty); }
} }
} }
@ -1108,7 +1106,7 @@ fn print_path(s: &ps, path: &ast::path) {
} }
if ivec::len(path.node.types) > 0u { if ivec::len(path.node.types) > 0u {
word(s.s, "["); word(s.s, "[");
commasep(s, inconsistent, path.node.types, print_boxed_type); commasep(s, inconsistent, path.node.types, print_type);
word(s.s, "]"); word(s.s, "]");
} }
} }
@ -1174,7 +1172,7 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl,
ibox(s, indent_unit); ibox(s, indent_unit);
word_space(s, x.ident + ":"); word_space(s, x.ident + ":");
print_alias(s, x.mode); print_alias(s, x.mode);
print_type(s, *x.ty); print_type(s, x.ty);
end(s); end(s);
} }
commasep(s, inconsistent, decl.inputs, print_arg); commasep(s, inconsistent, decl.inputs, print_arg);
@ -1184,7 +1182,7 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl,
if decl.output.node != ast::ty_nil { if decl.output.node != ast::ty_nil {
space_if_not_bol(s); space_if_not_bol(s);
word_space(s, "->"); word_space(s, "->");
print_type(s, *decl.output); print_type(s, decl.output);
} }
} }
@ -1316,7 +1314,7 @@ fn print_mutability(s: &ps, mut: &ast::mutability) {
fn print_mt(s: &ps, mt: &ast::mt) { fn print_mt(s: &ps, mt: &ast::mt) {
print_mutability(s, mt.mut); print_mutability(s, mt.mut);
print_type(s, *mt.ty); print_type(s, mt.ty);
} }
fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t[str], fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t[str],
@ -1329,7 +1327,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t[str],
popen(s); popen(s);
fn print_arg(s: &ps, input: &ast::ty_arg) { fn print_arg(s: &ps, input: &ast::ty_arg) {
print_alias(s, input.node.mode); print_alias(s, input.node.mode);
print_type(s, *input.node.ty); print_type(s, input.node.ty);
} }
commasep(s, inconsistent, inputs, print_arg); commasep(s, inconsistent, inputs, print_arg);
pclose(s); pclose(s);
@ -1339,7 +1337,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t[str],
ibox(s, indent_unit); ibox(s, indent_unit);
word_space(s, "->"); word_space(s, "->");
alt cf { alt cf {
ast::return. { print_type(s, *output); } ast::return. { print_type(s, output); }
ast::noreturn. { word_nbsp(s, "!"); } ast::noreturn. { word_nbsp(s, "!"); }
} }
end(s); end(s);

View file

@ -59,7 +59,7 @@ fn log_expr(e: &ast::expr) { log print::pprust::expr_to_str(@e); }
fn log_expr_err(e: &ast::expr) { log_err print::pprust::expr_to_str(@e); } fn log_expr_err(e: &ast::expr) { log_err print::pprust::expr_to_str(@e); }
fn log_ty_err(t: &ty) { log_err print::pprust::ty_to_str(t); } fn log_ty_err(t: &@ty) { log_err print::pprust::ty_to_str(t); }
fn log_pat_err(p: &@pat) { log_err print::pprust::pat_to_str(p); } fn log_pat_err(p: &@pat) { log_err print::pprust::pat_to_str(p); }