2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-17 17:28:44 -05:00
|
|
|
|
2013-04-24 03:29:46 -05:00
|
|
|
use metadata::encoder;
|
|
|
|
use middle::ty::{ReSkolemized, ReVar};
|
|
|
|
use middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid};
|
2013-05-02 10:11:15 -05:00
|
|
|
use middle::ty::{br_fresh, ctxt, field};
|
2013-05-07 16:30:21 -05:00
|
|
|
use middle::ty::{mt, t, param_ty};
|
2013-04-30 13:10:21 -05:00
|
|
|
use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region,
|
|
|
|
re_empty};
|
2013-09-03 18:24:12 -05:00
|
|
|
use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
|
2013-01-31 19:12:29 -06:00
|
|
|
use middle::ty::{ty_err, ty_estr, ty_evec, ty_float, ty_bare_fn, ty_closure};
|
2012-09-04 13:54:36 -05:00
|
|
|
use middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param};
|
2013-03-05 20:06:53 -06:00
|
|
|
use middle::ty::{ty_ptr, ty_rptr, ty_self, ty_tup, ty_type, ty_uniq};
|
2013-04-24 03:29:46 -05:00
|
|
|
use middle::ty::{ty_trait, ty_int};
|
2013-03-05 20:06:53 -06:00
|
|
|
use middle::ty::{ty_uint, ty_unboxed_vec, ty_infer};
|
2013-04-24 03:29:46 -05:00
|
|
|
use middle::ty;
|
|
|
|
use middle::typeck;
|
|
|
|
use syntax::abi::AbiSet;
|
|
|
|
use syntax::ast_map;
|
2013-09-15 11:50:17 -05:00
|
|
|
use syntax::codemap::{Span, Pos};
|
2013-05-14 19:27:27 -05:00
|
|
|
use syntax::parse::token;
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::print::pprust;
|
|
|
|
use syntax::{ast, ast_util};
|
2013-07-24 15:52:57 -05:00
|
|
|
use syntax::opt_vec;
|
|
|
|
use syntax::opt_vec::OptVec;
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-05-07 16:30:21 -05:00
|
|
|
/// Produces a string suitable for debugging output.
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
pub trait Repr {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str;
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:30:21 -05:00
|
|
|
/// Produces a string suitable for showing to the user.
|
|
|
|
pub trait UserString {
|
|
|
|
fn user_string(&self, tcx: ctxt) -> ~str;
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn note_and_explain_region(cx: ctxt,
|
2013-04-02 00:32:37 -05:00
|
|
|
prefix: &str,
|
2013-01-29 17:48:50 -06:00
|
|
|
region: ty::Region,
|
2013-04-02 00:32:37 -05:00
|
|
|
suffix: &str) {
|
2012-08-13 17:06:13 -05:00
|
|
|
match explain_region_and_span(cx, region) {
|
2012-12-04 12:50:00 -06:00
|
|
|
(ref str, Some(span)) => {
|
2012-08-13 17:06:13 -05:00
|
|
|
cx.sess.span_note(
|
|
|
|
span,
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{}{}{}", prefix, (*str), suffix));
|
2012-08-13 17:06:13 -05:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
(ref str, None) => {
|
2012-08-13 17:06:13 -05:00
|
|
|
cx.sess.note(
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{}{}{}", prefix, (*str), suffix));
|
2012-08-13 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a string like "the block at 27:31" that attempts to explain a
|
|
|
|
/// lifetime in a way it might plausibly be understood.
|
2013-01-29 17:48:50 -06:00
|
|
|
pub 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
|
2013-08-31 11:13:04 -05:00
|
|
|
-> (~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) => {
|
2013-02-05 21:41:45 -06:00
|
|
|
match cx.items.find(&node_id) {
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_block(ref blk)) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
explain_span(cx, "block", blk.span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2013-03-15 14:24:24 -05:00
|
|
|
Some(&ast_map::node_callee_scope(expr)) => {
|
|
|
|
explain_span(cx, "callee", expr.span)
|
|
|
|
}
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_expr(expr)) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match expr.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::ExprCall(*) => explain_span(cx, "call", expr.span),
|
|
|
|
ast::ExprMethodCall(*) => {
|
2013-01-05 21:33:37 -06:00
|
|
|
explain_span(cx, "method call", expr.span)
|
2012-11-30 13:18:25 -06:00
|
|
|
},
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::ExprMatch(*) => explain_span(cx, "match", expr.span),
|
2013-01-05 21:33:37 -06:00
|
|
|
_ => explain_span(cx, "expression", expr.span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_stmt(stmt)) => {
|
2013-01-19 19:06:36 -06:00
|
|
|
explain_span(cx, "statement", stmt.span)
|
|
|
|
}
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_item(it, _)) if (match it.node {
|
2013-01-20 21:47:04 -06:00
|
|
|
ast::item_fn(*) => true, _ => false}) => {
|
|
|
|
explain_span(cx, "function body", it.span)
|
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(_) | None => {
|
2012-07-31 23:08:24 -05:00
|
|
|
// this really should not happen
|
2013-09-28 00:38:08 -05:00
|
|
|
(format!("unknown scope: {}. Please report a bug.", node_id),
|
2012-08-20 14:23:37 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-02 00:32:37 -05:00
|
|
|
re_free(ref fr) => {
|
|
|
|
let prefix = match fr.bound_region {
|
2013-09-28 00:38:08 -05:00
|
|
|
br_anon(idx) => format!("the anonymous lifetime \\#{} defined on",
|
2012-08-20 18:53:33 -05:00
|
|
|
idx + 1),
|
2013-09-28 00:38:08 -05:00
|
|
|
br_fresh(_) => format!("an anonymous lifetime defined on"),
|
|
|
|
_ => format!("the lifetime {} as defined on",
|
2013-06-17 18:49:45 -05:00
|
|
|
bound_region_ptr_to_str(cx, fr.bound_region))
|
2012-08-20 18:53:33 -05:00
|
|
|
};
|
|
|
|
|
2013-04-02 00:32:37 -05:00
|
|
|
match cx.items.find(&fr.scope_id) {
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_block(ref blk)) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
let (msg, opt_span) = explain_span(cx, "block", blk.span);
|
2013-09-28 00:38:08 -05:00
|
|
|
(format!("{} {}", prefix, msg), opt_span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(_) | None => {
|
2012-07-31 23:08:24 -05:00
|
|
|
// this really should not happen
|
2013-09-28 00:38:08 -05:00
|
|
|
(format!("{} node {}", prefix, fr.scope_id), None)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
re_static => { (~"the static lifetime", None) }
|
2012-07-31 23:08:24 -05:00
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
re_empty => { (~"the empty lifetime", None) }
|
|
|
|
|
2012-08-07 21:48:24 -05:00
|
|
|
// I believe these cases should not occur (except when debugging,
|
|
|
|
// perhaps)
|
2012-10-19 08:01:01 -05:00
|
|
|
re_infer(_) | re_bound(_) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
(format!("lifetime {:?}", region), None)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn explain_span(cx: ctxt, heading: &str, span: Span)
|
|
|
|
-> (~str, Option<Span>)
|
2012-08-13 17:06:13 -05:00
|
|
|
{
|
2012-11-12 20:24:56 -06:00
|
|
|
let lo = cx.sess.codemap.lookup_char_pos_adj(span.lo);
|
2013-09-28 00:38:08 -05:00
|
|
|
(format!("the {} at {}:{}", heading,
|
2012-11-12 21:32:48 -06:00
|
|
|
lo.line, lo.col.to_uint()), Some(span))
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 18:49:45 -05:00
|
|
|
pub fn bound_region_ptr_to_str(cx: ctxt, br: bound_region) -> ~str {
|
|
|
|
bound_region_to_str(cx, "&", true, br)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
2012-08-20 18:53:33 -05:00
|
|
|
|
2013-06-17 18:49:45 -05:00
|
|
|
pub fn bound_region_to_str(cx: ctxt,
|
|
|
|
prefix: &str, space: bool,
|
|
|
|
br: bound_region) -> ~str {
|
|
|
|
let space_str = if space { " " } else { "" };
|
|
|
|
|
2013-09-28 00:38:08 -05:00
|
|
|
if cx.sess.verbose() { return format!("{}{:?}{}", prefix, br, space_str); }
|
2012-07-24 18:23:23 -05:00
|
|
|
|
2012-11-04 22:41:00 -06:00
|
|
|
match br {
|
2013-09-28 00:38:08 -05:00
|
|
|
br_named(id) => format!("{}'{}{}", prefix, cx.sess.str_of(id), space_str),
|
|
|
|
br_self => format!("{}'self{}", prefix, space_str),
|
2013-01-05 21:33:37 -06:00
|
|
|
br_anon(_) => prefix.to_str(),
|
2012-12-05 17:13:24 -06:00
|
|
|
br_fresh(_) => prefix.to_str(),
|
2013-06-17 18:49:45 -05:00
|
|
|
br_cap_avoid(_, br) => bound_region_to_str(cx, prefix, space, *br)
|
2012-04-01 16:28:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 03:25:59 -05:00
|
|
|
pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::NodeId) -> ~str {
|
2013-02-05 21:41:45 -06:00
|
|
|
match cx.items.find(&node_id) {
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_block(ref blk)) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("<block at {}>",
|
2013-02-18 00:20:36 -06:00
|
|
|
cx.sess.codemap.span_to_str(blk.span))
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
2013-03-23 20:45:27 -05:00
|
|
|
Some(&ast_map::node_expr(expr)) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match expr.node {
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::ExprCall(*) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("<call at {}>",
|
2012-11-12 20:24:56 -06:00
|
|
|
cx.sess.codemap.span_to_str(expr.span))
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::ExprMatch(*) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("<match at {}>",
|
2012-11-12 20:24:56 -06:00
|
|
|
cx.sess.codemap.span_to_str(expr.span))
|
2012-04-12 23:59:33 -05:00
|
|
|
}
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::ExprAssignOp(*) |
|
|
|
|
ast::ExprUnary(*) |
|
|
|
|
ast::ExprBinary(*) |
|
|
|
|
ast::ExprIndex(*) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("<method at {}>",
|
2012-11-12 20:24:56 -06:00
|
|
|
cx.sess.codemap.span_to_str(expr.span))
|
2012-06-01 17:46:32 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("<expression at {}>",
|
2012-11-12 20:24:56 -06:00
|
|
|
cx.sess.codemap.span_to_str(expr.span))
|
2012-07-26 10:51:57 -05:00
|
|
|
}
|
2012-03-15 21:05:38 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
None => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("<unknown-{}>", node_id)
|
2012-07-06 15:59:17 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { cx.sess.bug(
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("re_scope refers to {}",
|
2012-07-18 18:18:02 -05:00
|
|
|
ast_map::node_id_to_str(cx.items, node_id,
|
2013-05-14 19:27:27 -05:00
|
|
|
token::get_ident_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()`
|
2013-06-17 18:49:45 -05:00
|
|
|
pub fn region_ptr_to_str(cx: ctxt, region: Region) -> ~str {
|
|
|
|
region_to_str(cx, "&", true, region)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
|
2013-06-17 18:49:45 -05:00
|
|
|
pub fn region_to_str(cx: ctxt, prefix: &str, space: bool, region: Region) -> ~str {
|
|
|
|
let space_str = if space { " " } else { "" };
|
|
|
|
|
2012-09-12 19:06:36 -05:00
|
|
|
if cx.sess.verbose() {
|
2013-09-28 00:38:08 -05:00
|
|
|
return format!("{}{:?}{}", prefix, region, space_str);
|
2012-08-13 17:06:13 -05:00
|
|
|
}
|
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 {
|
2013-01-05 21:33:37 -06:00
|
|
|
re_scope(_) => prefix.to_str(),
|
2013-06-17 18:49:45 -05:00
|
|
|
re_bound(br) => bound_region_to_str(cx, prefix, space, br),
|
|
|
|
re_free(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
|
2012-11-04 22:41:00 -06:00
|
|
|
re_infer(ReSkolemized(_, br)) => {
|
2013-06-17 18:49:45 -05:00
|
|
|
bound_region_to_str(cx, prefix, space, br)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
2013-01-05 21:33:37 -06:00
|
|
|
re_infer(ReVar(_)) => prefix.to_str(),
|
2013-09-28 00:38:08 -05:00
|
|
|
re_static => format!("{}'static{}", prefix, space_str),
|
|
|
|
re_empty => format!("{}'<empty>{}", prefix, space_str)
|
2012-03-15 21:05:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 04:08:44 -05:00
|
|
|
pub fn mutability_to_str(m: ast::Mutability) -> ~str {
|
2013-04-02 02:40:57 -05:00
|
|
|
match m {
|
2013-09-01 20:45:37 -05:00
|
|
|
ast::MutMutable => ~"mut ",
|
|
|
|
ast::MutImmutable => ~"",
|
2013-04-02 02:40:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 00:17:42 -05:00
|
|
|
pub fn mt_to_str(cx: ctxt, m: &mt) -> ~str {
|
2013-04-02 00:32:37 -05:00
|
|
|
mt_to_str_wrapped(cx, "", m, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mt_to_str_wrapped(cx: ctxt, before: &str, m: &mt, after: &str) -> ~str {
|
2013-04-02 02:40:57 -05:00
|
|
|
let mstr = mutability_to_str(m.mutbl);
|
2013-09-28 00:38:08 -05:00
|
|
|
return format!("{}{}{}{}", mstr, before, ty_to_str(cx, m.ty), after);
|
2012-03-22 22:06:01 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match vs {
|
2013-09-28 00:38:08 -05:00
|
|
|
ty::vstore_fixed(n) => format!("{}", n),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::vstore_uniq => ~"~",
|
|
|
|
ty::vstore_box => ~"@",
|
2013-06-17 18:49:45 -05:00
|
|
|
ty::vstore_slice(r) => region_ptr_to_str(cx, r)
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-08 23:16:09 -06:00
|
|
|
pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
|
|
|
|
match s {
|
|
|
|
ty::UniqTraitStore => ~"~",
|
|
|
|
ty::BoxTraitStore => ~"@",
|
2013-06-17 18:49:45 -05:00
|
|
|
ty::RegionTraitStore(r) => region_ptr_to_str(cx, r)
|
2013-03-08 23:16:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 00:32:37 -05:00
|
|
|
pub fn vstore_ty_to_str(cx: ctxt, mt: &mt, vs: ty::vstore) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match vs {
|
2013-04-02 00:32:37 -05:00
|
|
|
ty::vstore_fixed(_) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("[{}, .. {}]", mt_to_str(cx, mt), vstore_to_str(cx, vs))
|
2013-04-02 00:32:37 -05:00
|
|
|
}
|
|
|
|
_ => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{}{}", vstore_to_str(cx, vs), mt_to_str_wrapped(cx, "[", mt, "]"))
|
2013-04-02 00:32:37 -05:00
|
|
|
}
|
2012-07-13 17:24:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 12:34:33 -05:00
|
|
|
pub fn vec_map_to_str<T>(ts: &[T], f: &fn(t: &T) -> ~str) -> ~str {
|
|
|
|
let tstrs = ts.map(f);
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("[{}]", tstrs.connect(", "))
|
2013-08-02 12:34:33 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn tys_to_str(cx: ctxt, ts: &[t]) -> ~str {
|
2013-08-02 12:34:33 -05:00
|
|
|
vec_map_to_str(ts, |t| ty_to_str(cx, *t))
|
2012-05-03 11:17:58 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn fn_sig_to_str(cx: ctxt, typ: &ty::FnSig) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("fn{} -> {}",
|
2013-04-26 21:13:38 -05:00
|
|
|
tys_to_str(cx, typ.inputs.map(|a| *a)),
|
2013-01-08 16:00:45 -06:00
|
|
|
ty_to_str(cx, typ.output))
|
|
|
|
}
|
|
|
|
|
2013-03-27 05:16:28 -05:00
|
|
|
pub fn trait_ref_to_str(cx: ctxt, trait_ref: &ty::TraitRef) -> ~str {
|
2013-05-07 16:30:21 -05:00
|
|
|
trait_ref.user_string(cx)
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
|
2013-04-26 21:13:38 -05:00
|
|
|
fn fn_input_to_str(cx: ctxt, input: ty::t) -> ~str {
|
|
|
|
ty_to_str(cx, input)
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
fn bare_fn_to_str(cx: ctxt,
|
|
|
|
purity: ast::purity,
|
2013-03-13 21:25:28 -05:00
|
|
|
abis: AbiSet,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: Option<ast::Ident>,
|
2013-04-24 03:29:46 -05:00
|
|
|
sig: &ty::FnSig)
|
|
|
|
-> ~str {
|
2013-10-29 17:06:13 -05:00
|
|
|
let mut s = if abis.is_rust() {
|
|
|
|
~""
|
|
|
|
} else {
|
|
|
|
format!("extern {} ", abis.to_str())
|
|
|
|
};
|
2013-01-31 19:12:29 -06:00
|
|
|
|
|
|
|
match purity {
|
|
|
|
ast::impure_fn => {}
|
|
|
|
_ => {
|
|
|
|
s.push_str(purity.to_str());
|
|
|
|
s.push_char(' ');
|
|
|
|
}
|
2012-05-25 01:44:58 -05:00
|
|
|
};
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
s.push_str("fn");
|
2012-11-04 22:41:00 -06:00
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
match ident {
|
|
|
|
Some(i) => {
|
|
|
|
s.push_char(' ');
|
2013-06-12 12:02:55 -05:00
|
|
|
s.push_str(cx.sess.str_of(i));
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
_ => { }
|
|
|
|
}
|
|
|
|
|
2013-10-29 17:06:13 -05:00
|
|
|
push_sig_to_str(cx, &mut s, '(', ')', sig);
|
2013-01-31 19:12:29 -06:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2013-10-29 17:06:13 -05:00
|
|
|
fn closure_to_str(cx: ctxt, cty: &ty::ClosureTy) -> ~str {
|
2013-10-28 17:22:49 -05:00
|
|
|
let is_proc =
|
|
|
|
(cty.sigil, cty.onceness) == (ast::OwnedSigil, ast::Once);
|
2013-10-29 17:06:13 -05:00
|
|
|
let is_borrowed_closure = cty.sigil == ast::BorrowedSigil;
|
2013-10-28 17:22:49 -05:00
|
|
|
|
2013-10-29 17:06:13 -05:00
|
|
|
let mut s = if is_proc || is_borrowed_closure {
|
2013-10-28 17:22:49 -05:00
|
|
|
~""
|
|
|
|
} else {
|
|
|
|
cty.sigil.to_str()
|
|
|
|
};
|
2013-01-31 19:12:29 -06:00
|
|
|
|
|
|
|
match (cty.sigil, cty.region) {
|
|
|
|
(ast::ManagedSigil, ty::re_static) |
|
|
|
|
(ast::OwnedSigil, ty::re_static) => {}
|
2012-11-04 22:41:00 -06:00
|
|
|
|
|
|
|
(_, region) => {
|
2013-06-17 18:49:45 -05:00
|
|
|
s.push_str(region_to_str(cx, "", true, region));
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
match cty.purity {
|
|
|
|
ast::impure_fn => {}
|
|
|
|
_ => {
|
|
|
|
s.push_str(cty.purity.to_str());
|
|
|
|
s.push_char(' ');
|
|
|
|
}
|
|
|
|
};
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2013-10-28 17:22:49 -05:00
|
|
|
if is_proc {
|
|
|
|
s.push_str("proc");
|
|
|
|
} else {
|
|
|
|
match cty.onceness {
|
|
|
|
ast::Many => {}
|
|
|
|
ast::Once => {
|
|
|
|
s.push_str(cty.onceness.to_str());
|
|
|
|
s.push_char(' ');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-29 17:06:13 -05:00
|
|
|
if !is_borrowed_closure {
|
|
|
|
s.push_str("fn");
|
|
|
|
}
|
2013-10-28 17:22:49 -05:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
|
2013-10-29 17:06:13 -05:00
|
|
|
if !is_borrowed_closure {
|
|
|
|
// Print bounds before `fn` if this is not a borrowed closure.
|
|
|
|
if !cty.bounds.is_empty() {
|
|
|
|
s.push_str(":");
|
|
|
|
s.push_str(cty.bounds.repr(cx));
|
|
|
|
}
|
|
|
|
|
|
|
|
push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
|
|
|
|
} else {
|
|
|
|
// Print bounds after the signature if this is a borrowed closure.
|
|
|
|
push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
|
2013-06-17 14:16:30 -05:00
|
|
|
|
2013-10-29 17:06:13 -05:00
|
|
|
if is_borrowed_closure {
|
|
|
|
if !cty.bounds.is_empty() {
|
|
|
|
s.push_str(":");
|
|
|
|
s.push_str(cty.bounds.repr(cx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2013-10-29 17:06:13 -05:00
|
|
|
fn push_sig_to_str(cx: ctxt,
|
|
|
|
s: &mut ~str,
|
|
|
|
bra: char,
|
|
|
|
ket: char,
|
|
|
|
sig: &ty::FnSig) {
|
|
|
|
s.push_char(bra);
|
2013-01-31 19:12:29 -06:00
|
|
|
let strs = sig.inputs.map(|a| fn_input_to_str(cx, *a));
|
2013-06-10 08:25:25 -05:00
|
|
|
s.push_str(strs.connect(", "));
|
2013-10-29 17:06:13 -05:00
|
|
|
s.push_char(ket);
|
2013-01-31 19:12:29 -06:00
|
|
|
if ty::get(sig.output).sty != ty_nil {
|
|
|
|
s.push_str(" -> ");
|
|
|
|
if ty::type_is_bot(sig.output) {
|
|
|
|
s.push_char('!');
|
2013-01-08 08:21:19 -06:00
|
|
|
} else {
|
2013-01-31 19:12:29 -06:00
|
|
|
s.push_str(ty_to_str(cx, sig.output));
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-02 10:11:15 -05:00
|
|
|
fn method_to_str(cx: ctxt, m: ty::Method) -> ~str {
|
2013-01-31 19:12:29 -06:00
|
|
|
bare_fn_to_str(cx,
|
|
|
|
m.fty.purity,
|
2013-03-13 21:25:28 -05:00
|
|
|
m.fty.abis,
|
2013-01-31 19:12:29 -06:00
|
|
|
Some(m.ident),
|
2013-05-23 11:09:11 -05:00
|
|
|
&m.fty.sig) + ";"
|
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 {
|
2013-09-28 00:38:08 -05:00
|
|
|
return format!("{}: {}", 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:
|
2013-08-03 11:45:23 -05:00
|
|
|
/*for def_id in ty::type_def_id(typ).iter() {
|
2012-05-04 14:33:04 -05:00
|
|
|
// note that this typedef cannot have type parameters
|
2012-09-19 18:55:01 -05:00
|
|
|
return ast_map::path_to_str(ty::item_path(cx, *def_id),
|
|
|
|
cx.sess.intr());
|
2013-01-07 16:16:52 -06:00
|
|
|
}*/
|
2012-02-10 12:28:35 -06:00
|
|
|
|
|
|
|
// pretty print the structural type representation:
|
2013-03-20 00:17:42 -05:00
|
|
|
return match ty::get(typ).sty {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_nil => ~"()",
|
2013-01-08 08:21:19 -06:00
|
|
|
ty_bot => ~"!",
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_bool => ~"bool",
|
2013-09-03 18:24:12 -05:00
|
|
|
ty_char => ~"char",
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_int(ast::ty_i) => ~"int",
|
|
|
|
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(t) => ast_util::float_ty_to_str(t),
|
2013-03-20 00:17:42 -05:00
|
|
|
ty_box(ref tm) => ~"@" + mt_to_str(cx, tm),
|
|
|
|
ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm),
|
|
|
|
ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
|
|
|
|
ty_rptr(r, ref tm) => {
|
2013-06-17 18:49:45 -05:00
|
|
|
region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
2013-09-28 00:38:08 -05:00
|
|
|
ty_unboxed_vec(ref tm) => { format!("unboxed_vec<{}>", mt_to_str(cx, tm)) }
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_type => ~"type",
|
2013-03-20 00:17:42 -05:00
|
|
|
ty_tup(ref elems) => {
|
2012-10-18 11:14:11 -05:00
|
|
|
let strs = elems.map(|elem| ty_to_str(cx, *elem));
|
2013-06-10 08:25:25 -05:00
|
|
|
~"(" + strs.connect(",") + ")"
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
ty_closure(ref f) => {
|
|
|
|
closure_to_str(cx, f)
|
|
|
|
}
|
|
|
|
ty_bare_fn(ref f) => {
|
2013-03-13 21:25:28 -05:00
|
|
|
bare_fn_to_str(cx, f.purity, f.abis, None, &f.sig)
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-09-06 14:30:15 -05:00
|
|
|
ty_infer(infer_ty) => infer_ty.to_str(),
|
2012-11-16 21:22:48 -06:00
|
|
|
ty_err => ~"[type error]",
|
2013-01-10 12:59:58 -06:00
|
|
|
ty_param(param_ty {idx: id, def_id: did}) => {
|
2013-06-21 12:36:50 -05:00
|
|
|
let param_def = cx.ty_param_defs.find(&did.node);
|
|
|
|
let ident = match param_def {
|
|
|
|
Some(def) => {
|
|
|
|
cx.sess.str_of(def.ident).to_owned()
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
// This should not happen...
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("BUG[{:?}]", id)
|
2013-06-21 12:36:50 -05:00
|
|
|
}
|
|
|
|
};
|
2013-09-28 00:38:08 -05:00
|
|
|
if !cx.sess.verbose() { ident } else { format!("{}:{:?}", ident, did) }
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2013-03-27 09:26:57 -05:00
|
|
|
ty_self(*) => ~"Self",
|
2012-12-10 15:47:54 -06:00
|
|
|
ty_enum(did, ref substs) | ty_struct(did, ref 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());
|
2013-07-24 15:52:57 -05:00
|
|
|
parameterized(cx, base, &substs.regions, substs.tps)
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
2013-06-17 14:16:30 -05:00
|
|
|
ty_trait(did, ref substs, s, mutbl, ref bounds) => {
|
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());
|
2013-07-24 15:52:57 -05:00
|
|
|
let ty = parameterized(cx, base, &substs.regions, substs.tps);
|
2013-06-19 21:27:06 -05:00
|
|
|
let bound_sep = if bounds.is_empty() { "" } else { ":" };
|
2013-06-17 14:16:30 -05:00
|
|
|
let bound_str = bounds.repr(cx);
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{}{}{}{}{}", trait_store_to_str(cx, s), mutability_to_str(mutbl), ty,
|
2013-06-19 21:27:06 -05:00
|
|
|
bound_sep, bound_str)
|
2012-02-10 08:01:32 -06:00
|
|
|
}
|
2013-03-20 00:17:42 -05:00
|
|
|
ty_evec(ref mt, vs) => {
|
2013-04-02 00:32:37 -05:00
|
|
|
vstore_ty_to_str(cx, mt, vs)
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
2013-09-28 00:38:08 -05:00
|
|
|
ty_estr(vs) => format!("{}{}", vstore_to_str(cx, vs), "str"),
|
2012-08-03 21:59:04 -05:00
|
|
|
ty_opaque_box => ~"@?",
|
2013-06-15 22:45:48 -05:00
|
|
|
ty_opaque_closure_ptr(ast::BorrowedSigil) => ~"&closure",
|
|
|
|
ty_opaque_closure_ptr(ast::ManagedSigil) => ~"@closure",
|
|
|
|
ty_opaque_closure_ptr(ast::OwnedSigil) => ~"~closure",
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub fn parameterized(cx: ctxt,
|
|
|
|
base: &str,
|
2013-07-24 15:52:57 -05:00
|
|
|
regions: &ty::RegionSubsts,
|
2013-01-29 17:48:50 -06:00
|
|
|
tps: &[ty::t]) -> ~str {
|
2012-04-23 18:01:03 -05:00
|
|
|
|
2013-06-17 18:49:45 -05:00
|
|
|
let mut strs = ~[];
|
2013-07-24 15:52:57 -05:00
|
|
|
match *regions {
|
|
|
|
ty::ErasedRegions => { }
|
|
|
|
ty::NonerasedRegions(ref regions) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for &r in regions.iter() {
|
2013-07-24 15:52:57 -05:00
|
|
|
strs.push(region_to_str(cx, "", false, r))
|
|
|
|
}
|
2013-06-15 22:45:48 -05:00
|
|
|
}
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
2012-04-23 18:01:03 -05:00
|
|
|
|
2013-08-03 11:45:23 -05:00
|
|
|
for t in tps.iter() {
|
2013-06-25 20:25:27 -05:00
|
|
|
strs.push(ty_to_str(cx, *t))
|
|
|
|
}
|
2013-06-17 18:49:45 -05:00
|
|
|
|
|
|
|
if strs.len() > 0u {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{}<{}>", base, strs.connect(","))
|
2012-04-23 18:01:03 -05:00
|
|
|
} else {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{}", base)
|
2012-04-23 18:01:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:48:50 -06:00
|
|
|
pub 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);
|
2013-06-09 09:44:58 -05:00
|
|
|
if s.len() >= 32u { s = s.slice(0u, 32u).to_owned(); }
|
2012-08-01 19:30:05 -05:00
|
|
|
return s;
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
impl<T:Repr> Repr for Option<T> {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
match self {
|
|
|
|
&None => ~"None",
|
2013-09-28 00:38:08 -05:00
|
|
|
&Some(ref t) => format!("Some({})", t.repr(tcx))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T:Repr> Repr for @T {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
(&**self).repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T:Repr> Repr for ~T {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
(&**self).repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn repr_vec<T:Repr>(tcx: ctxt, v: &[T]) -> ~str {
|
2013-08-02 12:34:33 -05:00
|
|
|
vec_map_to_str(v, |t| t.repr(tcx))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'self, T:Repr> Repr for &'self [T] {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
repr_vec(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 15:52:57 -05:00
|
|
|
impl<T:Repr> Repr for OptVec<T> {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
match *self {
|
|
|
|
opt_vec::Empty => ~"[]",
|
|
|
|
opt_vec::Vec(ref v) => repr_vec(tcx, *v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 18:54:28 -05:00
|
|
|
// This is necessary to handle types like Option<~[T]>, for which
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
// autoderef cannot convert the &[T] handler
|
2013-07-08 18:54:28 -05:00
|
|
|
impl<T:Repr> Repr for ~[T] {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-07-08 18:54:28 -05:00
|
|
|
repr_vec(tcx, *self)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::TypeParameterDef {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("TypeParameterDef \\{{:?}, bounds: {}\\}",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.def_id, self.bounds.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::t {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
ty_to_str(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::substs {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("substs(regions={}, self_ty={}, tps={})",
|
2013-07-24 15:52:57 -05:00
|
|
|
self.regions.repr(tcx),
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.self_ty.repr(tcx),
|
|
|
|
self.tps.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 15:52:57 -05:00
|
|
|
impl Repr for ty::RegionSubsts {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
match *self {
|
|
|
|
ty::ErasedRegions => ~"erased",
|
|
|
|
ty::NonerasedRegions(ref regions) => regions.repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:30:21 -05:00
|
|
|
impl Repr for ty::ParamBounds {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-05-07 16:30:21 -05:00
|
|
|
let mut res = ~[];
|
2013-07-25 23:53:29 -05:00
|
|
|
for b in self.builtin_bounds.iter() {
|
2013-05-07 16:30:21 -05:00
|
|
|
res.push(match b {
|
|
|
|
ty::BoundStatic => ~"'static",
|
2013-06-05 13:33:14 -05:00
|
|
|
ty::BoundSend => ~"Send",
|
2013-06-05 16:52:27 -05:00
|
|
|
ty::BoundFreeze => ~"Freeze",
|
2013-05-30 19:03:01 -05:00
|
|
|
ty::BoundSized => ~"Sized",
|
2013-05-07 16:30:21 -05:00
|
|
|
});
|
2013-07-25 23:53:29 -05:00
|
|
|
}
|
2013-08-03 11:45:23 -05:00
|
|
|
for t in self.trait_bounds.iter() {
|
2013-05-07 16:30:21 -05:00
|
|
|
res.push(t.repr(tcx));
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
2013-06-10 08:25:25 -05:00
|
|
|
res.connect("+")
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::TraitRef {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
trait_ref_to_str(tcx, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
impl Repr for ast::Expr {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("expr({}: {})",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.id,
|
2013-07-08 18:54:28 -05:00
|
|
|
pprust::expr_to_str(self, tcx.sess.intr()))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
impl Repr for ast::Pat {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("pat({}: {})",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.id,
|
2013-07-08 18:54:28 -05:00
|
|
|
pprust::pat_to_str(self, tcx.sess.intr()))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 20:37:37 -05:00
|
|
|
impl Repr for ty::bound_region {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-07-01 19:43:42 -05:00
|
|
|
bound_region_ptr_to_str(tcx, *self)
|
2013-05-23 20:37:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
impl Repr for ty::Region {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-06-17 18:49:45 -05:00
|
|
|
region_to_str(tcx, "", false, *self)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
impl Repr for ast::DefId {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
// Unfortunately, there seems to be no way to attempt to print
|
|
|
|
// a path for a def-id, so I'll just make a best effort for now
|
|
|
|
// and otherwise fallback to just printing the crate/node pair
|
2013-07-27 03:25:59 -05:00
|
|
|
if self.crate == ast::LOCAL_CRATE {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
match tcx.items.find(&self.node) {
|
|
|
|
Some(&ast_map::node_item(*)) |
|
|
|
|
Some(&ast_map::node_foreign_item(*)) |
|
|
|
|
Some(&ast_map::node_method(*)) |
|
|
|
|
Some(&ast_map::node_trait_method(*)) |
|
|
|
|
Some(&ast_map::node_variant(*)) |
|
|
|
|
Some(&ast_map::node_struct_ctor(*)) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
return format!("{:?}:{}", *self, ty::item_path_str(tcx, *self));
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2013-09-28 00:38:08 -05:00
|
|
|
return format!("{:?}", *self);
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::ty_param_bounds_and_ty {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("ty_param_bounds_and_ty \\{generics: {}, ty: {}\\}",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.generics.repr(tcx),
|
|
|
|
self.ty.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::Generics {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("Generics \\{type_param_defs: {}, region_param: {:?}\\}",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.type_param_defs.repr(tcx),
|
|
|
|
self.region_param)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 10:11:15 -05:00
|
|
|
impl Repr for ty::Method {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("method \\{ident: {}, generics: {}, transformed_self_ty: {}, \
|
|
|
|
fty: {}, explicit_self: {}, vis: {}, def_id: {}\\}",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.ident.repr(tcx),
|
|
|
|
self.generics.repr(tcx),
|
|
|
|
self.transformed_self_ty.repr(tcx),
|
|
|
|
self.fty.repr(tcx),
|
2013-04-30 10:49:48 -05:00
|
|
|
self.explicit_self.repr(tcx),
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.vis.repr(tcx),
|
|
|
|
self.def_id.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
impl Repr for ast::Ident {
|
2013-06-04 17:14:56 -05:00
|
|
|
fn repr(&self, _tcx: ctxt) -> ~str {
|
2013-06-12 12:02:55 -05:00
|
|
|
token::ident_to_str(self).to_owned()
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 10:49:48 -05:00
|
|
|
impl Repr for ast::explicit_self_ {
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
fn repr(&self, _tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{:?}", *self)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ast::visibility {
|
|
|
|
fn repr(&self, _tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{:?}", *self)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::BareFnTy {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("BareFnTy \\{purity: {:?}, abis: {}, sig: {}\\}",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.purity,
|
|
|
|
self.abis.to_str(),
|
|
|
|
self.sig.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::FnSig {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
fn_sig_to_str(tcx, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for typeck::method_map_entry {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("method_map_entry \\{self_arg: {}, \
|
|
|
|
explicit_self: {}, \
|
|
|
|
origin: {}\\}",
|
2013-04-26 21:13:38 -05:00
|
|
|
self.self_ty.repr(tcx),
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.explicit_self.repr(tcx),
|
|
|
|
self.origin.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for typeck::method_origin {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
match self {
|
|
|
|
&typeck::method_static(def_id) => {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("method_static({})", def_id.repr(tcx))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
&typeck::method_param(ref p) => {
|
|
|
|
p.repr(tcx)
|
|
|
|
}
|
2013-08-13 15:22:58 -05:00
|
|
|
&typeck::method_object(ref p) => {
|
|
|
|
p.repr(tcx)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for typeck::method_param {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("method_param({},{:?},{:?},{:?})",
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
self.trait_id.repr(tcx),
|
|
|
|
self.method_num,
|
|
|
|
self.param_num,
|
|
|
|
self.bound_num)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:22:58 -05:00
|
|
|
impl Repr for typeck::method_object {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("method_object({},{:?},{:?})",
|
2013-08-13 15:22:58 -05:00
|
|
|
self.trait_id.repr(tcx),
|
|
|
|
self.method_num,
|
|
|
|
self.real_index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-10 06:40:27 -05:00
|
|
|
impl Repr for ty::RegionVid {
|
2013-07-10 09:04:22 -05:00
|
|
|
fn repr(&self, _tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{:?}", *self)
|
2013-07-10 06:40:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
impl Repr for ty::TraitStore {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
match self {
|
|
|
|
&ty::BoxTraitStore => ~"@Trait",
|
|
|
|
&ty::UniqTraitStore => ~"~Trait",
|
2013-09-28 00:38:08 -05:00
|
|
|
&ty::RegionTraitStore(r) => format!("&{} Trait", r.repr(tcx))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 15:11:27 -05:00
|
|
|
impl Repr for ty::vstore {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
vstore_to_str(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
impl Repr for ast_map::path_elt {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
match *self {
|
|
|
|
ast_map::path_mod(id) => id.repr(tcx),
|
2013-08-30 02:47:10 -05:00
|
|
|
ast_map::path_name(id) => id.repr(tcx),
|
|
|
|
ast_map::path_pretty_name(id, _) => id.repr(tcx),
|
2013-03-15 14:24:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-07 16:30:21 -05:00
|
|
|
|
|
|
|
impl Repr for ty::BuiltinBound {
|
|
|
|
fn repr(&self, _tcx: ctxt) -> ~str {
|
2013-09-28 00:38:08 -05:00
|
|
|
format!("{:?}", *self)
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserString for ty::BuiltinBound {
|
|
|
|
fn user_string(&self, _tcx: ctxt) -> ~str {
|
|
|
|
match *self {
|
|
|
|
ty::BoundStatic => ~"'static",
|
2013-06-05 13:33:14 -05:00
|
|
|
ty::BoundSend => ~"Send",
|
2013-06-05 16:52:27 -05:00
|
|
|
ty::BoundFreeze => ~"Freeze",
|
2013-05-30 19:03:01 -05:00
|
|
|
ty::BoundSized => ~"Sized",
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::BuiltinBounds {
|
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
self.user_string(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
impl Repr for Span {
|
2013-05-23 20:37:37 -05:00
|
|
|
fn repr(&self, tcx: ctxt) -> ~str {
|
|
|
|
tcx.sess.codemap.span_to_str(*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A:UserString> UserString for @A {
|
|
|
|
fn user_string(&self, tcx: ctxt) -> ~str {
|
|
|
|
let this: &A = &**self;
|
|
|
|
this.user_string(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:30:21 -05:00
|
|
|
impl UserString for ty::BuiltinBounds {
|
|
|
|
fn user_string(&self, tcx: ctxt) -> ~str {
|
|
|
|
if self.is_empty() { ~"<no-bounds>" } else {
|
|
|
|
let mut result = ~[];
|
2013-07-25 23:53:29 -05:00
|
|
|
for bb in self.iter() {
|
2013-05-07 16:30:21 -05:00
|
|
|
result.push(bb.user_string(tcx));
|
2013-07-25 23:53:29 -05:00
|
|
|
}
|
2013-06-10 08:25:25 -05:00
|
|
|
result.connect("+")
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserString for ty::TraitRef {
|
|
|
|
fn user_string(&self, tcx: ctxt) -> ~str {
|
|
|
|
let path = ty::item_path(tcx, self.def_id);
|
|
|
|
let base = ast_map::path_to_str(path, tcx.sess.intr());
|
|
|
|
if tcx.sess.verbose() && self.substs.self_ty.is_some() {
|
2013-07-02 14:47:32 -05:00
|
|
|
let mut all_tps = self.substs.tps.clone();
|
2013-08-03 11:45:23 -05:00
|
|
|
for &t in self.substs.self_ty.iter() { all_tps.push(t); }
|
2013-07-24 15:52:57 -05:00
|
|
|
parameterized(tcx, base, &self.substs.regions, all_tps)
|
2013-05-07 16:30:21 -05:00
|
|
|
} else {
|
2013-07-24 15:52:57 -05:00
|
|
|
parameterized(tcx, base, &self.substs.regions, self.substs.tps)
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-22 05:54:35 -05:00
|
|
|
|
|
|
|
impl UserString for ty::t {
|
|
|
|
fn user_string(&self, tcx: ctxt) -> ~str {
|
|
|
|
ty_to_str(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
impl Repr for AbiSet {
|
|
|
|
fn repr(&self, _tcx: ctxt) -> ~str {
|
|
|
|
self.to_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserString for AbiSet {
|
|
|
|
fn user_string(&self, _tcx: ctxt) -> ~str {
|
|
|
|
self.to_str()
|
|
|
|
}
|
|
|
|
}
|