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
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
use middle::def;
|
2014-05-13 10:35:42 -05:00
|
|
|
use middle::subst;
|
2014-05-31 17:53:13 -05:00
|
|
|
use middle::subst::{VecPerParamSpace,Subst};
|
2013-04-24 03:29:46 -05:00
|
|
|
use middle::ty::{ReSkolemized, ReVar};
|
2013-10-29 09:34:11 -05:00
|
|
|
use middle::ty::{BoundRegion, BrAnon, BrNamed};
|
2013-12-08 01:55:28 -06:00
|
|
|
use middle::ty::{BrFresh, ctxt};
|
2014-05-31 17:53:13 -05:00
|
|
|
use middle::ty::{mt, t, ParamTy};
|
2013-10-29 09:34:11 -05:00
|
|
|
use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region,
|
|
|
|
ReEmpty};
|
2013-09-03 18:24:12 -05:00
|
|
|
use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
|
2013-12-31 20:09:50 -06:00
|
|
|
use middle::ty::{ty_err, ty_str, ty_vec, ty_float, ty_bare_fn, ty_closure};
|
2014-05-31 17:53:13 -05:00
|
|
|
use middle::ty::{ty_nil, ty_param, ty_ptr, ty_rptr, ty_tup};
|
2014-04-06 05:54:41 -05:00
|
|
|
use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer};
|
2013-04-24 03:29:46 -05:00
|
|
|
use middle::ty;
|
|
|
|
use middle::typeck;
|
2014-06-20 05:35:06 -05:00
|
|
|
use middle::typeck::infer;
|
|
|
|
use middle::typeck::infer::unify;
|
|
|
|
use VV = middle::typeck::infer::unify::VarValue;
|
|
|
|
use middle::typeck::infer::region_inference;
|
2014-03-08 14:36:22 -06:00
|
|
|
|
2014-04-21 18:21:52 -05:00
|
|
|
use std::rc::Rc;
|
2014-05-16 12:15:33 -05:00
|
|
|
use std::gc::Gc;
|
2014-04-02 03:19:41 -05:00
|
|
|
use syntax::abi;
|
2013-04-24 03:29:46 -05:00
|
|
|
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};
|
2014-03-19 09:52:37 -05:00
|
|
|
use syntax::owned_slice::OwnedSlice;
|
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 {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String;
|
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-07 16:30:21 -05:00
|
|
|
/// Produces a string suitable for showing to the user.
|
|
|
|
pub trait UserString {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String;
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
|
2014-03-05 21:07:47 -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,
|
2014-05-16 12:45:16 -05:00
|
|
|
format!("{}{}{}", prefix, *str, suffix).as_slice());
|
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(
|
2014-05-16 12:45:16 -05:00
|
|
|
format!("{}{}{}", prefix, *str, suffix).as_slice());
|
2012-08-13 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:07:47 -06:00
|
|
|
pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
|
2014-05-22 18:57:53 -05:00
|
|
|
-> (String, Option<Span>) {
|
2012-08-06 14:34:08 -05:00
|
|
|
return match region {
|
2013-10-29 09:34:11 -05:00
|
|
|
ReScope(node_id) => {
|
2014-02-13 23:07:09 -06:00
|
|
|
match cx.map.find(node_id) {
|
2014-01-17 06:23:09 -06:00
|
|
|
Some(ast_map::NodeBlock(ref blk)) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
explain_span(cx, "block", blk.span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2014-01-17 06:23:09 -06:00
|
|
|
Some(ast_map::NodeExpr(expr)) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match expr.node {
|
2013-11-28 14:22:53 -06: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-11-28 14:22:53 -06: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
|
|
|
}
|
|
|
|
}
|
2014-01-17 06:23:09 -06:00
|
|
|
Some(ast_map::NodeStmt(stmt)) => {
|
2013-01-19 19:06:36 -06:00
|
|
|
explain_span(cx, "statement", stmt.span)
|
|
|
|
}
|
2014-02-13 23:07:09 -06:00
|
|
|
Some(ast_map::NodeItem(it)) if (match it.node {
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::ItemFn(..) => true, _ => false}) => {
|
2013-01-20 21:47:04 -06:00
|
|
|
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
|
2014-05-27 22:44:58 -05:00
|
|
|
(format!("unknown scope: {}. Please report a bug.", node_id), None)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2012-08-07 21:48:24 -05:00
|
|
|
}
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ReFree(ref fr) => {
|
2013-04-02 00:32:37 -05:00
|
|
|
let prefix = match fr.bound_region {
|
2014-05-28 11:24:28 -05:00
|
|
|
BrAnon(idx) => {
|
|
|
|
format!("the anonymous lifetime #{} defined on", idx + 1)
|
|
|
|
}
|
2014-05-25 05:17:19 -05:00
|
|
|
BrFresh(_) => "an anonymous lifetime defined on".to_string(),
|
2014-05-09 20:45:36 -05:00
|
|
|
_ => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("the lifetime {} as defined on",
|
|
|
|
bound_region_ptr_to_str(cx, fr.bound_region))
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
2012-08-20 18:53:33 -05:00
|
|
|
};
|
|
|
|
|
2014-02-13 23:07:09 -06:00
|
|
|
match cx.map.find(fr.scope_id) {
|
2014-01-17 06:23:09 -06:00
|
|
|
Some(ast_map::NodeBlock(ref blk)) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
let (msg, opt_span) = explain_span(cx, "block", blk.span);
|
2014-05-27 22:44:58 -05:00
|
|
|
(format!("{} {}", prefix, msg), opt_span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2014-02-13 23:07:09 -06:00
|
|
|
Some(ast_map::NodeItem(it)) if match it.node {
|
2014-01-09 07:05:33 -06:00
|
|
|
ast::ItemImpl(..) => true, _ => false} => {
|
2013-10-29 05:03:32 -05:00
|
|
|
let (msg, opt_span) = explain_span(cx, "impl", it.span);
|
2014-05-27 22:44:58 -05:00
|
|
|
(format!("{} {}", prefix, msg), opt_span)
|
2013-10-29 05:03:32 -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
|
2014-05-27 22:44:58 -05:00
|
|
|
(format!("{} node {}", prefix, fr.scope_id), None)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-25 05:17:19 -05:00
|
|
|
ReStatic => { ("the static lifetime".to_string(), None) }
|
2012-07-31 23:08:24 -05:00
|
|
|
|
2014-05-25 05:17:19 -05:00
|
|
|
ReEmpty => { ("the empty lifetime".to_string(), None) }
|
2013-03-15 14:24:24 -05:00
|
|
|
|
2012-08-07 21:48:24 -05:00
|
|
|
// I believe these cases should not occur (except when debugging,
|
|
|
|
// perhaps)
|
2013-11-28 14:22:53 -06:00
|
|
|
ty::ReInfer(_) | ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
(format!("lifetime {:?}", region), None)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-05 21:07:47 -06:00
|
|
|
fn explain_span(cx: &ctxt, heading: &str, span: Span)
|
2014-05-22 18:57:53 -05:00
|
|
|
-> (String, Option<Span>) {
|
2014-03-16 13:56:24 -05:00
|
|
|
let lo = cx.sess.codemap().lookup_char_pos_adj(span.lo);
|
2014-05-27 22:44:58 -05:00
|
|
|
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_uint()),
|
|
|
|
Some(span))
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn bound_region_ptr_to_str(cx: &ctxt, br: BoundRegion) -> String {
|
2014-05-20 22:28:40 -05:00
|
|
|
bound_region_to_str(cx, "", false, br)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
2012-08-20 18:53:33 -05:00
|
|
|
|
2014-03-05 21:07:47 -06:00
|
|
|
pub fn bound_region_to_str(cx: &ctxt,
|
2013-06-17 18:49:45 -05:00
|
|
|
prefix: &str, space: bool,
|
2014-05-22 18:57:53 -05:00
|
|
|
br: BoundRegion) -> String {
|
2013-06-17 18:49:45 -05:00
|
|
|
let space_str = if space { " " } else { "" };
|
|
|
|
|
2013-10-29 05:03:32 -05:00
|
|
|
if cx.sess.verbose() {
|
2014-05-27 22:44:58 -05:00
|
|
|
return format!("{}{}{}", prefix, br.repr(cx), space_str)
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
2012-07-24 18:23:23 -05:00
|
|
|
|
2012-11-04 22:41:00 -06:00
|
|
|
match br {
|
2014-05-09 20:45:36 -05:00
|
|
|
BrNamed(_, name) => {
|
2014-06-10 15:54:13 -05:00
|
|
|
format!("{}{}{}", prefix, token::get_name(name), space_str)
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
2014-05-25 05:17:19 -05:00
|
|
|
BrAnon(_) => prefix.to_string(),
|
|
|
|
BrFresh(_) => prefix.to_string(),
|
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()`
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn region_ptr_to_str(cx: &ctxt, region: Region) -> String {
|
2013-06-17 18:49:45 -05:00
|
|
|
region_to_str(cx, "&", true, region)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn region_to_str(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
|
2013-06-17 18:49:45 -05:00
|
|
|
let space_str = if space { " " } else { "" };
|
|
|
|
|
2012-09-12 19:06:36 -05:00
|
|
|
if cx.sess.verbose() {
|
2014-05-27 22:44:58 -05:00
|
|
|
return format!("{}{}{}", prefix, region.repr(cx), 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 {
|
2014-05-25 05:17:19 -05:00
|
|
|
ty::ReScope(_) => prefix.to_string(),
|
2014-05-31 17:53:13 -05:00
|
|
|
ty::ReEarlyBound(_, _, _, name) => {
|
2014-05-25 05:17:19 -05:00
|
|
|
token::get_name(name).get().to_string()
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReLateBound(_, br) => bound_region_to_str(cx, prefix, space, br),
|
|
|
|
ty::ReFree(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
|
|
|
|
ty::ReInfer(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
|
|
|
}
|
2014-05-25 05:17:19 -05:00
|
|
|
ty::ReInfer(ReVar(_)) => prefix.to_string(),
|
2014-05-27 22:44:58 -05:00
|
|
|
ty::ReStatic => format!("{}'static{}", prefix, space_str),
|
|
|
|
ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
|
2012-03-15 21:05:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn mutability_to_str(m: ast::Mutability) -> String {
|
2013-04-02 02:40:57 -05:00
|
|
|
match m {
|
2014-05-25 05:17:19 -05:00
|
|
|
ast::MutMutable => "mut ".to_string(),
|
|
|
|
ast::MutImmutable => "".to_string(),
|
2013-04-02 02:40:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn mt_to_str(cx: &ctxt, m: &mt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{}{}", mutability_to_str(m.mutbl), ty_to_str(cx, m.ty))
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> String {
|
2013-03-08 23:16:09 -06:00
|
|
|
match s {
|
2014-05-25 05:17:19 -05:00
|
|
|
ty::UniqTraitStore => "Box ".to_string(),
|
2014-04-11 01:01:31 -05:00
|
|
|
ty::RegionTraitStore(r, m) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{}{}", region_ptr_to_str(cx, r), mutability_to_str(m))
|
2013-04-02 00:32:37 -05:00
|
|
|
}
|
2012-07-13 17:24:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn vec_map_to_str<T>(ts: &[T], f: |t: &T| -> String) -> String {
|
|
|
|
let tstrs = ts.iter().map(f).collect::<Vec<String>>();
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("[{}]", tstrs.connect(", "))
|
2013-08-02 12:34:33 -05:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn fn_sig_to_str(cx: &ctxt, typ: &ty::FnSig) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("fn{}{} -> {}", typ.binder_id, typ.inputs.repr(cx),
|
|
|
|
typ.output.repr(cx))
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn trait_ref_to_str(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
trait_ref.user_string(cx).to_string()
|
2013-03-27 05:16:28 -05:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn ty_to_str(cx: &ctxt, typ: t) -> String {
|
|
|
|
fn fn_input_to_str(cx: &ctxt, input: ty::t) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
ty_to_str(cx, input).to_string()
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2014-03-05 21:07:47 -06:00
|
|
|
fn bare_fn_to_str(cx: &ctxt,
|
2014-04-06 20:04:40 -05:00
|
|
|
fn_style: ast::FnStyle,
|
2014-04-02 03:19:41 -05:00
|
|
|
abi: abi::Abi,
|
2013-09-01 19:50:59 -05:00
|
|
|
ident: Option<ast::Ident>,
|
2013-04-24 03:29:46 -05:00
|
|
|
sig: &ty::FnSig)
|
2014-05-22 18:57:53 -05:00
|
|
|
-> String {
|
|
|
|
let mut s = String::new();
|
2014-04-06 20:04:40 -05:00
|
|
|
match fn_style {
|
|
|
|
ast::NormalFn => {}
|
2013-01-31 19:12:29 -06:00
|
|
|
_ => {
|
2014-05-16 12:45:16 -05:00
|
|
|
s.push_str(fn_style.to_str().as_slice());
|
2013-01-31 19:12:29 -06:00
|
|
|
s.push_char(' ');
|
|
|
|
}
|
2012-05-25 01:44:58 -05:00
|
|
|
};
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2014-05-09 18:30:57 -05:00
|
|
|
if abi != abi::Rust {
|
2014-05-16 12:45:16 -05:00
|
|
|
s.push_str(format!("extern {} ", abi.to_str()).as_slice());
|
2014-05-09 18:30:57 -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 {
|
2014-02-13 23:07:09 -06:00
|
|
|
Some(i) => {
|
|
|
|
s.push_char(' ');
|
|
|
|
s.push_str(token::get_ident(i).get());
|
|
|
|
}
|
|
|
|
_ => { }
|
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
|
|
|
|
2014-05-09 20:45:36 -05:00
|
|
|
s
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
2014-04-02 18:54:22 -05:00
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
fn closure_to_str(cx: &ctxt, cty: &ty::ClosureTy) -> String {
|
|
|
|
let mut s = String::new();
|
2013-10-28 17:22:49 -05:00
|
|
|
|
2014-04-11 10:03:10 -05:00
|
|
|
match cty.store {
|
|
|
|
ty::UniqTraitStore => {}
|
|
|
|
ty::RegionTraitStore(region, _) => {
|
2014-05-09 20:45:36 -05:00
|
|
|
s.push_str(region_to_str(cx, "", true, region).as_slice());
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-06 20:04:40 -05:00
|
|
|
match cty.fn_style {
|
|
|
|
ast::NormalFn => {}
|
2013-01-31 19:12:29 -06:00
|
|
|
_ => {
|
2014-05-16 12:45:16 -05:00
|
|
|
s.push_str(cty.fn_style.to_str().as_slice());
|
2013-01-31 19:12:29 -06:00
|
|
|
s.push_char(' ');
|
|
|
|
}
|
|
|
|
};
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2014-04-11 10:03:10 -05:00
|
|
|
match cty.store {
|
|
|
|
ty::UniqTraitStore => {
|
|
|
|
assert_eq!(cty.onceness, ast::Once);
|
|
|
|
s.push_str("proc");
|
|
|
|
push_sig_to_str(cx, &mut s, '(', ')', &cty.sig);
|
|
|
|
}
|
|
|
|
ty::RegionTraitStore(..) => {
|
|
|
|
match cty.onceness {
|
|
|
|
ast::Many => {}
|
|
|
|
ast::Once => s.push_str("once ")
|
2013-10-28 17:22:49 -05:00
|
|
|
}
|
2014-04-11 10:03:10 -05:00
|
|
|
push_sig_to_str(cx, &mut s, '|', '|', &cty.sig);
|
2013-10-29 17:06:13 -05:00
|
|
|
}
|
2013-10-28 17:22:49 -05:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
|
2014-04-11 10:03:10 -05:00
|
|
|
if !cty.bounds.is_empty() {
|
|
|
|
s.push_str(":");
|
2014-05-09 20:45:36 -05:00
|
|
|
s.push_str(cty.bounds.repr(cx).as_slice());
|
2013-10-29 17:06:13 -05:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
|
2014-05-09 20:45:36 -05:00
|
|
|
s
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
2014-04-02 18:54:22 -05:00
|
|
|
|
2014-03-05 21:07:47 -06:00
|
|
|
fn push_sig_to_str(cx: &ctxt,
|
2014-05-22 18:57:53 -05:00
|
|
|
s: &mut String,
|
2013-10-29 17:06:13 -05:00
|
|
|
bra: char,
|
|
|
|
ket: char,
|
|
|
|
sig: &ty::FnSig) {
|
|
|
|
s.push_char(bra);
|
2014-05-22 18:57:53 -05:00
|
|
|
let strs: Vec<String> = sig.inputs.iter().map(|a| fn_input_to_str(cx, *a)).collect();
|
2014-05-19 19:23:26 -05:00
|
|
|
s.push_str(strs.connect(", ").as_slice());
|
2013-10-25 00:56:34 -05:00
|
|
|
if sig.variadic {
|
|
|
|
s.push_str(", ...");
|
|
|
|
}
|
2013-10-29 17:06:13 -05:00
|
|
|
s.push_char(ket);
|
2013-10-25 00:56:34 -05:00
|
|
|
|
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 {
|
2014-05-09 20:45:36 -05:00
|
|
|
s.push_str(ty_to_str(cx, sig.output).as_slice());
|
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
|
2014-02-13 23:07:09 -06:00
|
|
|
return ty::item_path_str(cx, *def_id);
|
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 {
|
2014-05-25 05:17:19 -05:00
|
|
|
ty_nil => "()".to_string(),
|
|
|
|
ty_bot => "!".to_string(),
|
|
|
|
ty_bool => "bool".to_string(),
|
|
|
|
ty_char => "char".to_string(),
|
2014-04-21 16:58:52 -05:00
|
|
|
ty_int(t) => ast_util::int_ty_to_str(t, None).to_string(),
|
|
|
|
ty_uint(t) => ast_util::uint_ty_to_str(t, None).to_string(),
|
2014-05-25 05:17:19 -05:00
|
|
|
ty_float(t) => ast_util::float_ty_to_str(t).to_string(),
|
2014-06-15 12:04:55 -05:00
|
|
|
ty_box(typ) => format!("Gc<{}>", ty_to_str(cx, typ)),
|
|
|
|
ty_uniq(typ) => format!("Box<{}>", ty_to_str(cx, typ)),
|
2014-05-27 22:44:58 -05:00
|
|
|
ty_ptr(ref tm) => format!("*{}", mt_to_str(cx, tm)),
|
2013-03-20 00:17:42 -05:00
|
|
|
ty_rptr(r, ref tm) => {
|
2014-05-09 20:45:36 -05:00
|
|
|
let mut buf = region_ptr_to_str(cx, r);
|
|
|
|
buf.push_str(mt_to_str(cx, tm).as_slice());
|
|
|
|
buf
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
2013-03-20 00:17:42 -05:00
|
|
|
ty_tup(ref elems) => {
|
2014-05-22 18:57:53 -05:00
|
|
|
let strs: Vec<String> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("({})", strs.connect(","))
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
ty_closure(ref f) => {
|
2014-03-19 06:20:56 -05:00
|
|
|
closure_to_str(cx, *f)
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
ty_bare_fn(ref f) => {
|
2014-04-06 20:04:40 -05:00
|
|
|
bare_fn_to_str(cx, f.fn_style, f.abi, None, &f.sig)
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2014-06-05 02:15:19 -05:00
|
|
|
ty_infer(infer_ty) => infer_ty.to_str(),
|
2014-05-25 05:17:19 -05:00
|
|
|
ty_err => "[type error]".to_string(),
|
2014-05-31 17:53:13 -05:00
|
|
|
ty_param(ParamTy {idx: id, def_id: did, ..}) => {
|
2014-03-20 21:49:20 -05:00
|
|
|
let ident = match cx.ty_param_defs.borrow().find(&did.node) {
|
2014-05-25 05:17:19 -05:00
|
|
|
Some(def) => token::get_ident(def.ident).get().to_string(),
|
2014-04-12 03:16:37 -05:00
|
|
|
// This can only happen when a type mismatch error happens and
|
|
|
|
// the actual type has more type parameters than the expected one.
|
2014-05-28 11:24:28 -05:00
|
|
|
None => format!("<generic #{}>", id),
|
2013-06-21 12:36:50 -05:00
|
|
|
};
|
2014-02-13 23:07:09 -06:00
|
|
|
if !cx.sess.verbose() {
|
|
|
|
ident
|
|
|
|
} else {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{}:{:?}", ident, did)
|
2014-02-13 23:07:09 -06:00
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-12-10 15:47:54 -06:00
|
|
|
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
|
2014-05-31 17:53:13 -05:00
|
|
|
let base = ty::item_path_str(cx, did);
|
|
|
|
let generics = ty::lookup_item_type(cx, did).generics;
|
|
|
|
parameterized(cx, base.as_slice(), substs, &generics)
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
2014-05-05 20:56:44 -05:00
|
|
|
ty_trait(box ty::TyTrait {
|
2014-06-11 00:18:57 -05:00
|
|
|
def_id: did, ref substs, ref bounds
|
2014-03-19 06:01:30 -05:00
|
|
|
}) => {
|
2014-05-31 17:53:13 -05:00
|
|
|
let base = ty::item_path_str(cx, did);
|
|
|
|
let trait_def = ty::lookup_trait_def(cx, did);
|
|
|
|
let ty = parameterized(cx, base.as_slice(),
|
|
|
|
substs, &trait_def.generics);
|
|
|
|
let bound_sep = if bounds.is_empty() { "" } else { ":" };
|
|
|
|
let bound_str = bounds.repr(cx);
|
2014-06-11 00:18:57 -05:00
|
|
|
format!("{}{}{}",
|
2014-05-31 17:53:13 -05:00
|
|
|
ty,
|
|
|
|
bound_sep,
|
|
|
|
bound_str)
|
2014-04-11 01:01:31 -05:00
|
|
|
}
|
2014-05-25 05:17:19 -05:00
|
|
|
ty_str => "str".to_string(),
|
2014-04-09 02:15:31 -05:00
|
|
|
ty_vec(ref mt, sz) => {
|
|
|
|
match sz {
|
2014-05-09 20:45:36 -05:00
|
|
|
Some(n) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("[{}, .. {}]", mt_to_str(cx, mt), n)
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
2014-05-27 22:44:58 -05:00
|
|
|
None => format!("[{}]", ty_to_str(cx, mt.ty)),
|
2014-04-09 02:15:31 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-03-05 21:07:47 -06:00
|
|
|
pub fn parameterized(cx: &ctxt,
|
2013-01-29 17:48:50 -06:00
|
|
|
base: &str,
|
2014-05-31 17:53:13 -05:00
|
|
|
substs: &subst::Substs,
|
|
|
|
generics: &ty::Generics)
|
|
|
|
-> String
|
|
|
|
{
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut strs = Vec::new();
|
2014-05-31 17:53:13 -05:00
|
|
|
|
|
|
|
match substs.regions {
|
2014-05-13 10:35:42 -05:00
|
|
|
subst::ErasedRegions => { }
|
|
|
|
subst::NonerasedRegions(ref regions) => {
|
2013-08-03 11:45:23 -05:00
|
|
|
for &r in regions.iter() {
|
2014-05-31 17:53:13 -05:00
|
|
|
let s = region_to_str(cx, "", false, r);
|
|
|
|
if !s.is_empty() {
|
|
|
|
strs.push(s)
|
|
|
|
} else {
|
|
|
|
// This happens when the value of the region
|
|
|
|
// parameter is not easily serialized. This may be
|
|
|
|
// because the user omitted it in the first place,
|
|
|
|
// or because it refers to some block in the code,
|
|
|
|
// etc. I'm not sure how best to serialize this.
|
|
|
|
strs.push(format!("'_"));
|
|
|
|
}
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
2013-06-15 22:45:48 -05:00
|
|
|
}
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
2012-04-23 18:01:03 -05:00
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
let tps = substs.types.get_vec(subst::TypeSpace);
|
|
|
|
let ty_params = generics.types.get_vec(subst::TypeSpace);
|
2014-02-02 04:53:23 -06:00
|
|
|
let has_defaults = ty_params.last().map_or(false, |def| def.default.is_some());
|
2014-05-31 17:53:13 -05:00
|
|
|
let num_defaults = if has_defaults && !cx.sess.verbose() {
|
2014-02-02 04:53:23 -06:00
|
|
|
ty_params.iter().zip(tps.iter()).rev().take_while(|&(def, &actual)| {
|
|
|
|
match def.default {
|
2014-05-31 17:53:13 -05:00
|
|
|
Some(default) => default.subst(cx, substs) == actual,
|
2014-02-02 04:53:23 -06:00
|
|
|
None => false
|
|
|
|
}
|
2014-06-06 01:18:51 -05:00
|
|
|
}).count()
|
2014-02-02 04:53:23 -06:00
|
|
|
} else {
|
|
|
|
0
|
|
|
|
};
|
2014-01-30 11:28:02 -06:00
|
|
|
|
|
|
|
for t in tps.slice_to(tps.len() - num_defaults).iter() {
|
2013-06-25 20:25:27 -05:00
|
|
|
strs.push(ty_to_str(cx, *t))
|
|
|
|
}
|
2013-06-17 18:49:45 -05:00
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
if cx.sess.verbose() {
|
|
|
|
for t in substs.types.get_vec(subst::SelfSpace).iter() {
|
|
|
|
strs.push(format!("for {}", t.repr(cx)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 18:49:45 -05:00
|
|
|
if strs.len() > 0u {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{}<{}>", base, strs.connect(","))
|
2012-04-23 18:01:03 -05:00
|
|
|
} else {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{}", base)
|
2012-04-23 18:01:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn ty_to_short_str(cx: &ctxt, typ: t) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
let mut s = typ.repr(cx).to_string();
|
2014-05-09 20:45:36 -05:00
|
|
|
if s.len() >= 32u {
|
2014-05-25 05:17:19 -05:00
|
|
|
s = s.as_slice().slice(0u, 32u).to_string();
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
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> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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 self {
|
2014-05-25 05:17:19 -05:00
|
|
|
&None => "None".to_string(),
|
2014-02-07 13:51:18 -06:00
|
|
|
&Some(ref 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 13:51:18 -06:00
|
|
|
impl<T:Repr,U:Repr> Repr for Result<T,U> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-02-07 13:51:18 -06:00
|
|
|
match self {
|
|
|
|
&Ok(ref t) => t.repr(tcx),
|
2014-05-27 22:44:58 -05:00
|
|
|
&Err(ref u) => format!("Err({})", u.repr(tcx))
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for () {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
"()".to_string()
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-21 18:21:52 -05:00
|
|
|
impl<T:Repr> Repr for Rc<T> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-04-21 18:21:52 -05:00
|
|
|
(&**self).repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 20:18:00 -05:00
|
|
|
impl<T:Repr + 'static> Repr for Gc<T> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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).repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 20:56:44 -05:00
|
|
|
impl<T:Repr> Repr for Box<T> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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).repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr_vec<T:Repr>(tcx: &ctxt, v: &[T]) -> String {
|
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
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'a, T:Repr> Repr for &'a [T] {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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
|
|
|
repr_vec(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 09:52:37 -05:00
|
|
|
impl<T:Repr> Repr for OwnedSlice<T> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-03-19 09:52:37 -05:00
|
|
|
repr_vec(tcx, self.as_slice())
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2014-03-04 12:02:49 -06:00
|
|
|
impl<T:Repr> Repr for Vec<T> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-03-08 14:36:22 -06:00
|
|
|
repr_vec(tcx, self.as_slice())
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
impl Repr for def::Def {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
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::TypeParameterDef {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("TypeParameterDef({:?}, {})", self.def_id,
|
|
|
|
self.bounds.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::RegionParameterDef {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("RegionParameterDef({}, {:?})",
|
|
|
|
token::get_name(self.name),
|
|
|
|
self.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::t {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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
|
|
|
ty_to_str(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 05:35:06 -05:00
|
|
|
impl Repr for ty::mt {
|
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
mt_to_str(tcx, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 10:35:42 -05:00
|
|
|
impl Repr for subst::Substs {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-31 17:53:13 -05:00
|
|
|
format!("Substs[types={}, regions={}]",
|
|
|
|
self.types.repr(tcx),
|
|
|
|
self.regions.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T:Repr> Repr for subst::VecPerParamSpace<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
format!("[{};{};{}]",
|
|
|
|
self.get_vec(subst::TypeSpace).repr(tcx),
|
|
|
|
self.get_vec(subst::SelfSpace).repr(tcx),
|
|
|
|
self.get_vec(subst::FnSpace).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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 06:20:15 -05:00
|
|
|
impl Repr for ty::ItemSubsts {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("ItemSubsts({})", self.substs.repr(tcx))
|
2014-05-07 06:20:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 10:35:42 -05:00
|
|
|
impl Repr for subst::RegionSubsts {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2013-07-24 15:52:57 -05:00
|
|
|
match *self {
|
2014-05-13 10:35:42 -05:00
|
|
|
subst::ErasedRegions => "erased".to_string(),
|
|
|
|
subst::NonerasedRegions(ref regions) => regions.repr(tcx)
|
2013-07-24 15:52:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:30:21 -05:00
|
|
|
impl Repr for ty::ParamBounds {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut res = Vec::new();
|
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 {
|
2014-05-25 05:17:19 -05:00
|
|
|
ty::BoundStatic => "'static".to_string(),
|
|
|
|
ty::BoundSend => "Send".to_string(),
|
|
|
|
ty::BoundSized => "Sized".to_string(),
|
|
|
|
ty::BoundCopy => "Copy".to_string(),
|
|
|
|
ty::BoundShare => "Share".to_string(),
|
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
|
|
|
}
|
2014-05-25 05:17:19 -05:00
|
|
|
res.connect("+").to_string()
|
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 {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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
|
|
|
trait_ref_to_str(tcx, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
impl Repr for ast::Expr {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("expr({}: {})", self.id, pprust::expr_to_str(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
impl Repr for ast::Path {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("path({})", pprust::path_to_str(self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl Repr for ast::Item {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("item({})", tcx.map.node_to_str(self.id))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
impl Repr for ast::Stmt {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("stmt({}: {})",
|
|
|
|
ast_util::stmt_id(self),
|
|
|
|
pprust::stmt_to_str(self))
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
impl Repr for ast::Pat {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("pat({}: {})", self.id, pprust::pat_to_str(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-10-29 09:34:11 -05:00
|
|
|
impl Repr for ty::BoundRegion {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2013-10-29 05:03:32 -05:00
|
|
|
match *self {
|
2014-05-27 22:44:58 -05:00
|
|
|
ty::BrAnon(id) => format!("BrAnon({})", id),
|
2014-05-09 20:45:36 -05:00
|
|
|
ty::BrNamed(id, name) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("BrNamed({}, {})", id.repr(tcx), token::get_name(name))
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
2014-05-27 22:44:58 -05:00
|
|
|
ty::BrFresh(id) => format!("BrFresh({})", id),
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
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 {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2013-10-29 05:03:32 -05:00
|
|
|
match *self {
|
2014-05-31 17:53:13 -05:00
|
|
|
ty::ReEarlyBound(id, space, index, name) => {
|
|
|
|
format!("ReEarlyBound({}, {}, {}, {})",
|
|
|
|
id,
|
|
|
|
space,
|
|
|
|
index,
|
|
|
|
token::get_name(name))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReLateBound(binder_id, ref bound_region) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("ReLateBound({}, {})",
|
|
|
|
binder_id,
|
|
|
|
bound_region.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReFree(ref fr) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("ReFree({}, {})",
|
|
|
|
fr.scope_id,
|
|
|
|
fr.bound_region.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReScope(id) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("ReScope({})", id)
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReStatic => {
|
2014-05-25 05:17:19 -05:00
|
|
|
"ReStatic".to_string()
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReInfer(ReVar(ref vid)) => {
|
2014-06-20 05:35:06 -05:00
|
|
|
format!("ReInfer({})", vid.index)
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
|
2014-05-31 17:53:13 -05:00
|
|
|
format!("re_skolemized({}, {})", id, bound_region.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReEmpty => {
|
2014-05-25 05:17:19 -05:00
|
|
|
"ReEmpty".to_string()
|
2013-10-29 05:03:32 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
impl Repr for ast::DefId {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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
|
|
|
// 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
|
2014-02-05 15:15:24 -06:00
|
|
|
if self.krate == ast::LOCAL_CRATE {
|
2013-12-27 18:09:29 -06:00
|
|
|
{
|
2014-02-13 23:07:09 -06:00
|
|
|
match tcx.map.find(self.node) {
|
2014-01-17 06:23:09 -06:00
|
|
|
Some(ast_map::NodeItem(..)) |
|
|
|
|
Some(ast_map::NodeForeignItem(..)) |
|
|
|
|
Some(ast_map::NodeMethod(..)) |
|
|
|
|
Some(ast_map::NodeTraitMethod(..)) |
|
|
|
|
Some(ast_map::NodeVariant(..)) |
|
|
|
|
Some(ast_map::NodeStructCtor(..)) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
return format!(
|
2014-05-09 20:45:36 -05:00
|
|
|
"{:?}:{}",
|
|
|
|
*self,
|
|
|
|
ty::item_path_str(tcx, *self))
|
2013-12-27 18:09:29 -06: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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-27 22:44:58 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 14:59:45 -05:00
|
|
|
impl Repr for ty::Polytype {
|
2014-05-28 11:24:28 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-06 14:59:45 -05:00
|
|
|
format!("Polytype {{generics: {}, ty: {}}}",
|
2014-05-28 11:24:28 -05:00
|
|
|
self.generics.repr(tcx),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::Generics {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-31 17:53:13 -05:00
|
|
|
format!("Generics(types: {}, regions: {})",
|
|
|
|
self.types.repr(tcx),
|
|
|
|
self.regions.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::ItemVariances {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-31 17:53:13 -05:00
|
|
|
format!("ItemVariances(types={}, \
|
|
|
|
regions={})",
|
|
|
|
self.types.repr(tcx),
|
|
|
|
self.regions.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::Variance {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _: &ctxt) -> String {
|
2014-06-05 02:15:19 -05:00
|
|
|
// The first `.to_str()` returns a &'static str (it is not an implementation
|
|
|
|
// of the ToStr trait). Because of that, we need to call `.to_str()` again
|
|
|
|
// if we want to have a `String`.
|
|
|
|
self.to_str().to_str()
|
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-02 10:11:15 -05:00
|
|
|
impl Repr for ty::Method {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("method(ident: {}, generics: {}, fty: {}, \
|
|
|
|
explicit_self: {}, vis: {}, def_id: {})",
|
|
|
|
self.ident.repr(tcx),
|
|
|
|
self.generics.repr(tcx),
|
|
|
|
self.fty.repr(tcx),
|
|
|
|
self.explicit_self.repr(tcx),
|
|
|
|
self.vis.repr(tcx),
|
|
|
|
self.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-07 01:43:39 -06:00
|
|
|
impl Repr for ast::Name {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
token::get_name(*self).get().to_string()
|
2014-03-07 01:43:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
impl Repr for ast::Ident {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
token::get_ident(*self).get().to_string()
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl Repr for ast::ExplicitSelf_ {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl Repr for ast::Visibility {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -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 {
|
2014-05-28 11:24:28 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
format!("BareFnTy {{fn_style: {:?}, abi: {}, sig: {}}}",
|
|
|
|
self.fn_style,
|
|
|
|
self.abi.to_str(),
|
|
|
|
self.sig.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 ty::FnSig {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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_sig_to_str(tcx, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:06:45 -06:00
|
|
|
impl Repr for typeck::MethodCallee {
|
2014-05-28 11:24:28 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
format!("MethodCallee {{origin: {}, ty: {}, {}}}",
|
|
|
|
self.origin.repr(tcx),
|
|
|
|
self.ty.repr(tcx),
|
|
|
|
self.substs.repr(tcx))
|
|
|
|
}
|
2014-02-26 08:06:45 -06:00
|
|
|
}
|
|
|
|
|
2014-02-26 08:01:36 -06:00
|
|
|
impl Repr for typeck::MethodOrigin {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
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 self {
|
2014-02-26 08:01:36 -06:00
|
|
|
&typeck::MethodStatic(def_id) => {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("MethodStatic({})", 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
|
|
|
}
|
2014-02-26 08:01:36 -06:00
|
|
|
&typeck::MethodParam(ref p) => {
|
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
|
|
|
p.repr(tcx)
|
|
|
|
}
|
2014-02-26 08:01:36 -06:00
|
|
|
&typeck::MethodObject(ref p) => {
|
2013-08-13 15:22:58 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:01:36 -06:00
|
|
|
impl Repr for typeck::MethodParam {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("MethodParam({},{:?},{:?},{:?})",
|
|
|
|
self.trait_id.repr(tcx),
|
|
|
|
self.method_num,
|
|
|
|
self.param_num,
|
|
|
|
self.bound_num)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:01:36 -06:00
|
|
|
impl Repr for typeck::MethodObject {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("MethodObject({},{:?},{:?})",
|
|
|
|
self.trait_id.repr(tcx),
|
|
|
|
self.method_num,
|
|
|
|
self.real_index)
|
2013-08-13 15:22:58 -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 {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-04-11 01:01:31 -05:00
|
|
|
trait_store_to_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-05-07 16:30:21 -05:00
|
|
|
impl Repr for ty::BuiltinBound {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{:?}", *self)
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserString for ty::BuiltinBound {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, _tcx: &ctxt) -> String {
|
2013-05-07 16:30:21 -05:00
|
|
|
match *self {
|
2014-05-25 05:17:19 -05:00
|
|
|
ty::BoundStatic => "'static".to_string(),
|
|
|
|
ty::BoundSend => "Send".to_string(),
|
|
|
|
ty::BoundSized => "Sized".to_string(),
|
|
|
|
ty::BoundCopy => "Copy".to_string(),
|
|
|
|
ty::BoundShare => "Share".to_string(),
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::BuiltinBounds {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2013-05-07 16:30:21 -05:00
|
|
|
self.user_string(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
impl Repr for Span {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
tcx.sess.codemap().span_to_str(*self).to_string()
|
2013-05-23 20:37:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-21 18:21:52 -05:00
|
|
|
impl<A:UserString> UserString for Rc<A> {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
2013-05-23 20:37:37 -05:00
|
|
|
let this: &A = &**self;
|
|
|
|
this.user_string(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:30:21 -05:00
|
|
|
impl UserString for ty::BuiltinBounds {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
2014-05-09 20:45:36 -05:00
|
|
|
self.iter()
|
|
|
|
.map(|bb| bb.user_string(tcx))
|
2014-05-22 18:57:53 -05:00
|
|
|
.collect::<Vec<String>>()
|
2014-05-09 20:45:36 -05:00
|
|
|
.connect("+")
|
2014-05-25 05:17:19 -05:00
|
|
|
.to_string()
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserString for ty::TraitRef {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
2014-02-13 23:07:09 -06:00
|
|
|
let base = ty::item_path_str(tcx, self.def_id);
|
2014-05-31 17:53:13 -05:00
|
|
|
let trait_def = ty::lookup_trait_def(tcx, self.def_id);
|
|
|
|
parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics)
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-22 05:54:35 -05:00
|
|
|
|
|
|
|
impl UserString for ty::t {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
2013-05-22 05:54:35 -05:00
|
|
|
ty_to_str(tcx, *self)
|
|
|
|
}
|
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-03-07 01:43:39 -06:00
|
|
|
impl UserString for ast::Ident {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, _tcx: &ctxt) -> String {
|
2014-05-25 05:17:19 -05:00
|
|
|
token::get_name(self.name).get().to_string()
|
2014-03-07 01:43:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-02 03:19:41 -05:00
|
|
|
impl Repr for abi::Abi {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-06-05 02:15:19 -05:00
|
|
|
self.to_str()
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-02 03:19:41 -05:00
|
|
|
impl UserString for abi::Abi {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, _tcx: &ctxt) -> String {
|
2014-06-05 02:15:19 -05:00
|
|
|
self.to_str()
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-07 13:51:18 -06:00
|
|
|
|
|
|
|
impl Repr for ty::UpvarId {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("UpvarId({};`{}`;{})",
|
|
|
|
self.var_id,
|
|
|
|
ty::local_var_name_str(tcx, self.var_id),
|
|
|
|
self.closure_expr_id)
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ast::Mutability {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{:?}", *self)
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::BorrowKind {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{:?}", *self)
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::UpvarBorrow {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("UpvarBorrow({}, {})",
|
|
|
|
self.kind.repr(tcx),
|
|
|
|
self.region.repr(tcx))
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 05:35:06 -05:00
|
|
|
|
|
|
|
impl Repr for ty::IntVid {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::FloatVid {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::RegionVid {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::TyVid {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ty::IntVarValue {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{:?}", *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ast::IntTy {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{:?}", *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ast::UintTy {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{:?}", *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for ast::FloatTy {
|
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{:?}", *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T:Repr> Repr for infer::Bounds<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
format!("({} <= {})",
|
|
|
|
self.lb.repr(tcx),
|
|
|
|
self.ub.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<K:Repr,V:Repr> Repr for VV<K,V> {
|
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
match *self {
|
|
|
|
unify::Redirect(ref k) =>
|
|
|
|
format!("Redirect({})", k.repr(tcx)),
|
|
|
|
unify::Root(ref v, r) =>
|
|
|
|
format!("Root({}, {})", v.repr(tcx), r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repr for region_inference::VarValue {
|
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
match *self {
|
|
|
|
infer::region_inference::NoValue =>
|
|
|
|
format!("NoValue"),
|
|
|
|
infer::region_inference::Value(r) =>
|
|
|
|
format!("Value({})", r.repr(tcx)),
|
|
|
|
infer::region_inference::ErrorValue =>
|
|
|
|
format!("ErrorValue"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|