2012-03-15 21:05:38 -05:00
|
|
|
import std::map::hashmap;
|
2011-07-05 04:48:19 -05:00
|
|
|
import middle::ty;
|
2012-07-24 18:23:23 -05:00
|
|
|
import middle::ty::{arg, canon_mode};
|
|
|
|
import middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid};
|
2012-07-13 20:43:52 -05:00
|
|
|
import middle::ty::{ck_block, ck_box, ck_uniq, ctxt, field, method};
|
2012-07-31 23:08:24 -05:00
|
|
|
import middle::ty::{mt, t};
|
|
|
|
import middle::ty::{re_bound, re_free, re_scope, re_var, re_static, region};
|
2012-07-13 20:43:52 -05:00
|
|
|
import middle::ty::{ty_bool, ty_bot, ty_box, ty_class, ty_enum};
|
2012-07-03 18:30:42 -05:00
|
|
|
import middle::ty::{ty_estr, ty_evec, ty_float, ty_fn, ty_trait, ty_int};
|
2012-06-06 16:19:52 -05:00
|
|
|
import middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param};
|
2012-07-14 14:19:36 -05:00
|
|
|
import middle::ty::{ty_ptr, ty_rec, ty_rptr, ty_self, ty_tup};
|
2012-06-06 16:19:52 -05:00
|
|
|
import middle::ty::{ty_type, ty_uniq, ty_uint, ty_var, ty_var_integral};
|
2012-07-14 14:19:36 -05:00
|
|
|
import middle::ty::{ty_unboxed_vec, vid};
|
2011-07-07 14:47:39 -05:00
|
|
|
import metadata::encoder;
|
2012-03-15 21:05:38 -05:00
|
|
|
import syntax::codemap;
|
2012-07-31 23:08:24 -05:00
|
|
|
import syntax::codemap::span;
|
2011-11-10 10:41:42 -06:00
|
|
|
import syntax::print::pprust;
|
2012-07-13 20:43:52 -05:00
|
|
|
import syntax::print::pprust::{path_to_str, proto_to_str,
|
2012-05-25 01:44:58 -05:00
|
|
|
mode_to_str, purity_to_str};
|
2011-12-07 14:06:12 -06:00
|
|
|
import syntax::{ast, ast_util};
|
2012-05-22 01:34:34 -05:00
|
|
|
import syntax::ast_map;
|
2012-02-10 12:28:35 -06:00
|
|
|
import driver::session::session;
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2012-08-13 17:06:13 -05:00
|
|
|
fn note_and_explain_region(cx: ctxt, prefix: ~str, region: ty::region) {
|
|
|
|
match explain_region_and_span(cx, region) {
|
|
|
|
(str, some(span)) => {
|
|
|
|
cx.sess.span_note(
|
|
|
|
span,
|
|
|
|
fmt!("%s %s", prefix, str));
|
|
|
|
}
|
|
|
|
(str, none) => {
|
|
|
|
cx.sess.note(
|
|
|
|
fmt!("%s %s", prefix, str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a string like "the block at 27:31" that attempts to explain a
|
|
|
|
/// lifetime in a way it might plausibly be understood.
|
2012-07-31 23:08:24 -05:00
|
|
|
fn explain_region(cx: ctxt, region: ty::region) -> ~str {
|
2012-08-13 17:06:13 -05:00
|
|
|
let (res, _) = explain_region_and_span(cx, region);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn explain_region_and_span(cx: ctxt, region: ty::region)
|
|
|
|
-> (~str, option<span>)
|
|
|
|
{
|
2012-08-06 14:34:08 -05:00
|
|
|
return match region {
|
2012-07-31 23:08:24 -05:00
|
|
|
re_scope(node_id) => {
|
2012-08-07 21:48:24 -05:00
|
|
|
match cx.items.find(node_id) {
|
2012-07-31 23:08:24 -05:00
|
|
|
some(ast_map::node_block(blk)) => {
|
|
|
|
explain_span(cx, ~"block", blk.span)
|
|
|
|
}
|
|
|
|
some(ast_map::node_expr(expr)) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match expr.node {
|
2012-08-13 17:06:13 -05:00
|
|
|
ast::expr_call(*) => explain_span(cx, ~"call", expr.span),
|
|
|
|
ast::expr_match(*) => explain_span(cx, ~"alt", expr.span),
|
|
|
|
_ => explain_span(cx, ~"expression", expr.span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
some(_) | none => {
|
|
|
|
// this really should not happen
|
2012-08-13 17:06:13 -05:00
|
|
|
(fmt!("unknown scope: %d. Please report a bug.", node_id),
|
|
|
|
none)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2012-08-07 21:48:24 -05:00
|
|
|
}
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
re_free(id, br) => {
|
2012-08-20 18:53:33 -05:00
|
|
|
let prefix = match br {
|
|
|
|
br_anon(idx) => fmt!("the anonymous lifetime #%u defined on",
|
|
|
|
idx + 1),
|
|
|
|
_ => fmt!("the lifetime %s as defined on",
|
|
|
|
bound_region_to_str(cx, br))
|
|
|
|
};
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match cx.items.find(id) {
|
2012-07-31 23:08:24 -05:00
|
|
|
some(ast_map::node_block(blk)) => {
|
2012-08-13 17:06:13 -05:00
|
|
|
let (msg, opt_span) = explain_span(cx, ~"block", blk.span);
|
2012-08-20 18:53:33 -05:00
|
|
|
(fmt!("%s %s", prefix, msg), opt_span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
some(_) | none => {
|
|
|
|
// this really should not happen
|
2012-08-20 18:53:33 -05:00
|
|
|
(fmt!("%s node %d", prefix, id), none)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 17:06:13 -05:00
|
|
|
re_static => { (~"the static lifetime", none) }
|
2012-07-31 23:08:24 -05:00
|
|
|
|
2012-08-07 21:48:24 -05:00
|
|
|
// I believe these cases should not occur (except when debugging,
|
|
|
|
// perhaps)
|
2012-07-31 23:08:24 -05:00
|
|
|
re_var(_) | re_bound(_) => {
|
2012-08-13 17:06:13 -05:00
|
|
|
(fmt!("lifetime %?", region), none)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-13 17:06:13 -05:00
|
|
|
fn explain_span(cx: ctxt, heading: ~str, span: span)
|
|
|
|
-> (~str, option<span>)
|
|
|
|
{
|
2012-07-31 23:08:24 -05:00
|
|
|
let lo = codemap::lookup_char_pos_adj(cx.sess.codemap, span.lo);
|
2012-08-22 19:24:52 -05:00
|
|
|
(fmt!("the %s at %u:%u", heading, lo.line, lo.col), some(span))
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn bound_region_to_str(cx: ctxt, br: bound_region) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match br {
|
2012-07-18 18:18:02 -05:00
|
|
|
br_named(id) => fmt!("&%s", cx.sess.str_of(id)),
|
2012-08-20 18:53:33 -05:00
|
|
|
br_self if cx.sess.ppregions() => ~"&<self>",
|
|
|
|
br_self => ~"&self",
|
|
|
|
|
|
|
|
br_anon(idx) => {
|
|
|
|
if cx.sess.ppregions() {fmt!("&%u", idx)} else {~"&"}
|
|
|
|
}
|
2012-07-24 18:23:23 -05:00
|
|
|
|
|
|
|
// FIXME(#3011) -- even if this arm is removed, exhaustiveness checking
|
|
|
|
// does not fail
|
|
|
|
br_cap_avoid(id, br) => {
|
|
|
|
if cx.sess.ppregions() {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("br_cap_avoid(%?, %s)", id, bound_region_to_str(cx, *br))
|
2012-07-24 18:23:23 -05:00
|
|
|
} else {
|
|
|
|
bound_region_to_str(cx, *br)
|
|
|
|
}
|
|
|
|
}
|
2012-04-01 16:28:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match cx.items.find(node_id) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(ast_map::node_block(blk)) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("<block at %s>",
|
|
|
|
codemap::span_to_str(blk.span, cx.sess.codemap))
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
some(ast_map::node_expr(expr)) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match expr.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_call(*) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("<call at %s>",
|
|
|
|
codemap::span_to_str(expr.span, cx.sess.codemap))
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
2012-08-07 15:35:51 -05:00
|
|
|
ast::expr_match(*) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("<alt at %s>",
|
|
|
|
codemap::span_to_str(expr.span, cx.sess.codemap))
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
2012-07-06 11:14:57 -05:00
|
|
|
ast::expr_assign_op(*) |
|
|
|
|
ast::expr_field(*) |
|
|
|
|
ast::expr_unary(*) |
|
|
|
|
ast::expr_binary(*) |
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_index(*) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("<method at %s>",
|
|
|
|
codemap::span_to_str(expr.span, cx.sess.codemap))
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("<expression at %s>",
|
|
|
|
codemap::span_to_str(expr.span, cx.sess.codemap))
|
2012-07-26 10:51:57 -05:00
|
|
|
}
|
2012-03-15 21:05:38 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("<unknown-%d>", node_id)
|
2012-07-06 15:59:17 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { cx.sess.bug(
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("re_scope refers to %s",
|
2012-07-18 18:18:02 -05:00
|
|
|
ast_map::node_id_to_str(cx.items, node_id,
|
2012-08-22 19:24:52 -05:00
|
|
|
cx.sess.parse_sess.interner))) }
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-01 16:28:30 -05:00
|
|
|
|
2012-08-13 17:06:13 -05:00
|
|
|
// In general, if you are giving a region error message,
|
|
|
|
// you should use `explain_region()` or, better yet,
|
|
|
|
// `note_and_explain_region()`
|
2012-07-14 00:57:48 -05:00
|
|
|
fn region_to_str(cx: ctxt, region: region) -> ~str {
|
2012-08-13 17:06:13 -05:00
|
|
|
if cx.sess.ppregions() {
|
|
|
|
return fmt!("&%?", region);
|
|
|
|
}
|
2012-04-01 16:28:30 -05:00
|
|
|
|
2012-08-13 17:06:13 -05:00
|
|
|
// These printouts are concise. They do not contain all the information
|
|
|
|
// the user might want to diagnose an error, but there is basically no way
|
|
|
|
// to fit that into a short string. Hence the recommendation to use
|
|
|
|
// `explain_region()` or `note_and_explain_region()`.
|
|
|
|
match region {
|
2012-08-25 20:38:21 -05:00
|
|
|
re_scope(_) => ~"&",
|
2012-08-13 17:06:13 -05:00
|
|
|
re_bound(br) => bound_region_to_str(cx, br),
|
2012-08-25 20:38:21 -05:00
|
|
|
re_free(_, br) => bound_region_to_str(cx, br),
|
|
|
|
re_var(_) => ~"&",
|
2012-08-03 21:59:04 -05:00
|
|
|
re_static => ~"&static"
|
2012-03-15 21:05:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn mt_to_str(cx: ctxt, m: mt) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
let mstr = match m.mutbl {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::m_mutbl => ~"mut ",
|
|
|
|
ast::m_imm => ~"",
|
|
|
|
ast::m_const => ~"const "
|
2012-03-22 22:06:01 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return mstr + ty_to_str(cx, m.ty);
|
2012-03-22 22:06:01 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match vs {
|
2012-08-22 19:24:52 -05:00
|
|
|
ty::vstore_fixed(n) => fmt!("%u", n),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_uniq => ~"~",
|
|
|
|
ty::vstore_box => ~"@",
|
|
|
|
ty::vstore_slice(r) => region_to_str(cx, r)
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match vs {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_fixed(_) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("%s/%s", ty, vstore_to_str(cx, vs))
|
2012-07-13 17:24:41 -05:00
|
|
|
}
|
2012-08-24 17:28:43 -05:00
|
|
|
ty::vstore_slice(_) => {
|
|
|
|
fmt!("%s/%s", vstore_to_str(cx, vs), ty)
|
|
|
|
}
|
2012-08-22 19:24:52 -05:00
|
|
|
_ => fmt!("%s%s", vstore_to_str(cx, vs), ty)
|
2012-07-13 17:24:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-10 20:15:08 -05:00
|
|
|
fn proto_ty_to_str(cx: ctxt, proto: ty::fn_proto) -> ~str {
|
|
|
|
match proto {
|
|
|
|
ty::proto_bare => ~"",
|
|
|
|
ty::proto_vstore(vstore) => vstore_to_str(cx, vstore)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn tys_to_str(cx: ctxt, ts: ~[t]) -> ~str {
|
|
|
|
let mut rs = ~"";
|
2012-06-30 18:19:07 -05:00
|
|
|
for ts.each |t| { rs += ty_to_str(cx, t); }
|
2012-05-03 11:17:58 -05:00
|
|
|
rs
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn ty_to_str(cx: ctxt, typ: t) -> ~str {
|
2012-01-30 23:00:57 -06:00
|
|
|
fn fn_input_to_str(cx: ctxt, input: {mode: ast::mode, ty: t}) ->
|
2012-07-14 00:57:48 -05:00
|
|
|
~str {
|
2012-02-03 19:10:29 -06:00
|
|
|
let {mode, ty} = input;
|
2012-08-06 14:34:08 -05:00
|
|
|
let modestr = match canon_mode(cx, mode) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::infer(_) => ~"",
|
|
|
|
ast::expl(m) => {
|
2012-05-09 08:09:58 -05:00
|
|
|
if !ty::type_needs_infer(ty) &&
|
2012-02-03 08:15:28 -06:00
|
|
|
m == ty::default_arg_mode_for_ty(ty) {
|
2012-07-14 00:57:48 -05:00
|
|
|
~""
|
2012-02-03 19:10:29 -06:00
|
|
|
} else {
|
|
|
|
mode_to_str(ast::expl(m))
|
|
|
|
}
|
|
|
|
}
|
2012-01-16 04:32:38 -06:00
|
|
|
};
|
2012-02-03 19:10:29 -06:00
|
|
|
modestr + ty_to_str(cx, ty)
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2012-08-10 20:15:08 -05:00
|
|
|
fn fn_to_str(cx: ctxt, purity: ast::purity, proto: ty::fn_proto,
|
2012-05-25 01:44:58 -05:00
|
|
|
ident: option<ast::ident>,
|
2012-07-13 20:43:52 -05:00
|
|
|
inputs: ~[arg], output: t, cf: ast::ret_style) -> ~str {
|
2012-05-25 01:44:58 -05:00
|
|
|
let mut s;
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
s = match purity {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::impure_fn => ~"",
|
|
|
|
_ => purity_to_str(purity) + ~" "
|
2012-05-25 01:44:58 -05:00
|
|
|
};
|
2012-08-10 20:15:08 -05:00
|
|
|
|
|
|
|
s += ~"fn";
|
|
|
|
|
|
|
|
s += proto_ty_to_str(cx, proto);
|
2012-08-06 14:34:08 -05:00
|
|
|
match ident {
|
2012-07-18 18:18:02 -05:00
|
|
|
some(i) => { s += ~" "; s += cx.sess.str_of(i); }
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { }
|
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
s += ~"(";
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut strs = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for inputs.each |a| { vec::push(strs, fn_input_to_str(cx, a)); }
|
2012-07-14 00:57:48 -05:00
|
|
|
s += str::connect(strs, ~", ");
|
|
|
|
s += ~")";
|
2012-02-03 08:15:28 -06:00
|
|
|
if ty::get(output).struct != ty_nil {
|
2012-07-14 00:57:48 -05:00
|
|
|
s += ~" -> ";
|
2012-08-06 14:34:08 -05:00
|
|
|
match cf {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::noreturn => { s += ~"!"; }
|
|
|
|
ast::return_val => { s += ty_to_str(cx, output); }
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return s;
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn method_to_str(cx: ctxt, m: method) -> ~str {
|
2012-08-01 19:30:05 -05:00
|
|
|
return fn_to_str(
|
2012-05-25 01:44:58 -05:00
|
|
|
cx, m.fty.purity, m.fty.proto, some(m.ident), m.fty.inputs,
|
2012-07-13 20:43:52 -05:00
|
|
|
m.fty.output, m.fty.ret_style) + ~";";
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
fn field_to_str(cx: ctxt, f: field) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
return cx.sess.str_of(f.ident) + ~": " + mt_to_str(cx, f.mt);
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2012-02-10 12:28:35 -06:00
|
|
|
|
|
|
|
// if there is an id, print that instead of the structural type:
|
2012-06-30 18:19:07 -05:00
|
|
|
for ty::type_def_id(typ).each |def_id| {
|
2012-05-04 14:33:04 -05:00
|
|
|
// note that this typedef cannot have type parameters
|
2012-07-18 18:18:02 -05:00
|
|
|
return ast_map::path_to_str(ty::item_path(cx, def_id),cx.sess.intr());
|
2011-12-19 06:52:58 -06:00
|
|
|
}
|
2012-02-10 12:28:35 -06:00
|
|
|
|
|
|
|
// pretty print the structural type representation:
|
2012-08-06 14:34:08 -05:00
|
|
|
return match ty::get(typ).struct {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_nil => ~"()",
|
|
|
|
ty_bot => ~"_|_",
|
|
|
|
ty_bool => ~"bool",
|
|
|
|
ty_int(ast::ty_i) => ~"int",
|
|
|
|
ty_int(ast::ty_char) => ~"char",
|
|
|
|
ty_int(t) => ast_util::int_ty_to_str(t),
|
|
|
|
ty_uint(ast::ty_u) => ~"uint",
|
|
|
|
ty_uint(t) => ast_util::uint_ty_to_str(t),
|
|
|
|
ty_float(ast::ty_f) => ~"float",
|
|
|
|
ty_float(t) => ast_util::float_ty_to_str(t),
|
|
|
|
ty_box(tm) => ~"@" + mt_to_str(cx, tm),
|
|
|
|
ty_uniq(tm) => ~"~" + mt_to_str(cx, tm),
|
|
|
|
ty_ptr(tm) => ~"*" + mt_to_str(cx, tm),
|
|
|
|
ty_rptr(r, tm) => {
|
2012-04-13 15:35:57 -05:00
|
|
|
let rs = region_to_str(cx, r);
|
2012-07-14 00:57:48 -05:00
|
|
|
if rs == ~"&" {
|
2012-04-13 15:35:57 -05:00
|
|
|
rs + mt_to_str(cx, tm)
|
|
|
|
} else {
|
2012-07-14 00:57:48 -05:00
|
|
|
rs + ~"/" + mt_to_str(cx, tm)
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" }
|
|
|
|
ty_type => ~"type",
|
|
|
|
ty_rec(elems) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut strs: ~[~str] = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for elems.each |fld| { vec::push(strs, field_to_str(cx, fld)); }
|
2012-07-14 00:57:48 -05:00
|
|
|
~"{" + str::connect(strs, ~",") + ~"}"
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_tup(elems) => {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut strs = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for elems.each |elem| { vec::push(strs, ty_to_str(cx, elem)); }
|
2012-07-14 00:57:48 -05:00
|
|
|
~"(" + str::connect(strs, ~",") + ~")"
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_fn(f) => {
|
2012-05-25 01:44:58 -05:00
|
|
|
fn_to_str(cx, f.purity, f.proto, none, f.inputs,
|
2012-07-13 20:43:52 -05:00
|
|
|
f.output, f.ret_style)
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_var(v) => v.to_str(),
|
|
|
|
ty_var_integral(v) => v.to_str(),
|
|
|
|
ty_param({idx: id, _}) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
~"'" + str::from_bytes(~[('a' as u8) + (id as u8)])
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_self => ~"self",
|
|
|
|
ty_enum(did, substs) | ty_class(did, substs) => {
|
2012-04-18 23:26:25 -05:00
|
|
|
let path = ty::item_path(cx, did);
|
2012-07-18 18:18:02 -05:00
|
|
|
let base = ast_map::path_to_str(path, cx.sess.intr());
|
2012-04-18 23:26:25 -05:00
|
|
|
parameterized(cx, base, substs.self_r, substs.tps)
|
|
|
|
}
|
2012-08-14 17:27:06 -05:00
|
|
|
ty_trait(did, substs, vs) => {
|
2012-02-10 08:01:32 -06:00
|
|
|
let path = ty::item_path(cx, did);
|
2012-07-18 18:18:02 -05:00
|
|
|
let base = ast_map::path_to_str(path, cx.sess.intr());
|
2012-08-14 17:27:06 -05:00
|
|
|
let result = parameterized(cx, base, substs.self_r, substs.tps);
|
|
|
|
vstore_ty_to_str(cx, result, vs)
|
2012-02-10 08:01:32 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_evec(mt, vs) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
vstore_ty_to_str(cx, fmt!("[%s]", mt_to_str(cx, mt)), vs)
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs),
|
|
|
|
ty_opaque_box => ~"@?",
|
|
|
|
ty_opaque_closure_ptr(ck_block) => ~"closure&",
|
|
|
|
ty_opaque_closure_ptr(ck_box) => ~"closure@",
|
|
|
|
ty_opaque_closure_ptr(ck_uniq) => ~"closure~"
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2012-04-23 18:01:03 -05:00
|
|
|
fn parameterized(cx: ctxt,
|
2012-07-14 00:57:48 -05:00
|
|
|
base: ~str,
|
2012-04-23 18:01:03 -05:00
|
|
|
self_r: option<ty::region>,
|
2012-07-14 00:57:48 -05:00
|
|
|
tps: ~[ty::t]) -> ~str {
|
2012-04-23 18:01:03 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let r_str = match self_r {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => ~"",
|
|
|
|
some(r) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("/%s", region_to_str(cx, r))
|
2012-04-23 18:01:03 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if vec::len(tps) > 0u {
|
2012-06-30 18:19:07 -05:00
|
|
|
let strs = vec::map(tps, |t| ty_to_str(cx, t) );
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("%s%s<%s>", base, r_str, str::connect(strs, ~","))
|
2012-04-23 18:01:03 -05:00
|
|
|
} else {
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("%s%s", base, r_str)
|
2012-04-23 18:01:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn ty_to_short_str(cx: ctxt, typ: t) -> ~str {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut s = encoder::encoded_ty(cx, typ);
|
2012-02-23 03:44:04 -06:00
|
|
|
if str::len(s) >= 32u { s = str::slice(s, 0u, 32u); }
|
2012-08-01 19:30:05 -05:00
|
|
|
return s;
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|