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;
|
|
|
|
use middle::subst::{VecPerParamSpace,Subst};
|
2014-08-18 10:29:44 -05:00
|
|
|
use middle::subst;
|
2013-10-29 09:34:11 -05:00
|
|
|
use middle::ty::{BoundRegion, BrAnon, BrNamed};
|
2014-05-06 18:37:32 -05:00
|
|
|
use middle::ty::{ReEarlyBound, BrFresh, ctxt};
|
2014-07-04 18:45:47 -05:00
|
|
|
use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
|
2014-10-07 22:04:45 -05:00
|
|
|
use middle::ty::{ReSkolemized, ReVar, BrEnv};
|
2014-09-13 13:09:25 -05:00
|
|
|
use middle::ty::{mt, Ty, ParamTy};
|
2014-10-24 14:14:37 -05:00
|
|
|
use middle::ty::{ty_bool, ty_char, 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-11-04 06:57:21 -06:00
|
|
|
use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open};
|
2014-05-29 00:26:56 -05:00
|
|
|
use middle::ty::{ty_unboxed_closure};
|
2014-08-18 10:29:44 -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;
|
2014-12-12 10:28:35 -06:00
|
|
|
use middle::ty_fold::TypeFoldable;
|
2014-03-08 14:36:22 -06:00
|
|
|
|
2014-12-12 10:28:35 -06:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::hash::{Hash, Hasher};
|
2014-08-18 10:29:44 -05:00
|
|
|
use std::rc::Rc;
|
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;
|
2014-10-31 04:44:10 -05:00
|
|
|
use syntax::ptr::P;
|
2012-09-04 13:54:36 -05:00
|
|
|
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.
|
2014-09-29 14:11:30 -05:00
|
|
|
pub trait Repr<'tcx> for Sized? {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> 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.
|
2014-12-12 10:28:35 -06:00
|
|
|
pub trait UserString<'tcx> : Repr<'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> 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,
|
2014-10-17 21:39:44 -05:00
|
|
|
suffix: &str) -> Option<Span> {
|
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-12-10 21:46:38 -06:00
|
|
|
format!("{}{}{}", prefix, *str, suffix)[]);
|
2014-10-17 21:39:44 -05:00
|
|
|
Some(span)
|
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-12-10 21:46:38 -06:00
|
|
|
format!("{}{}{}", prefix, *str, suffix)[]);
|
2014-10-17 21:39:44 -05:00
|
|
|
None
|
2012-08-13 17:06:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// When a free region is associated with `item`, how should we describe the item in the error
|
|
|
|
/// message.
|
2014-08-27 20:46:52 -05:00
|
|
|
fn item_scope_tag(item: &ast::Item) -> &'static str {
|
|
|
|
match item.node {
|
|
|
|
ast::ItemImpl(..) => "impl",
|
|
|
|
ast::ItemStruct(..) => "struct",
|
|
|
|
ast::ItemEnum(..) => "enum",
|
|
|
|
ast::ItemTrait(..) => "trait",
|
|
|
|
ast::ItemFn(..) => "function body",
|
|
|
|
_ => "item"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2014-11-18 07:22:59 -06:00
|
|
|
ReScope(scope) => {
|
|
|
|
match cx.map.find(scope.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
|
|
|
},
|
2014-12-19 16:58:02 -06:00
|
|
|
ast::ExprMatch(_, _, ast::MatchSource::IfLetDesugar { .. }) =>
|
|
|
|
explain_span(cx, "if let", expr.span),
|
|
|
|
ast::ExprMatch(_, _, ast::MatchSource::WhileLetDesugar) => {
|
2014-10-02 23:41:24 -05:00
|
|
|
explain_span(cx, "while let", expr.span)
|
|
|
|
},
|
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-08-27 20:46:52 -05:00
|
|
|
Some(ast_map::NodeItem(it)) => {
|
|
|
|
let tag = item_scope_tag(&*it);
|
|
|
|
explain_span(cx, tag, it.span)
|
2013-01-20 21:47:04 -06: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-11-18 07:22:59 -06:00
|
|
|
(format!("unknown scope: {}. Please report a bug.", scope), 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",
|
2014-06-21 05:39:03 -05:00
|
|
|
bound_region_ptr_to_string(cx, fr.bound_region))
|
2014-05-09 20:45:36 -05:00
|
|
|
}
|
2012-08-20 18:53:33 -05:00
|
|
|
};
|
|
|
|
|
2014-11-18 07:22:59 -06:00
|
|
|
match cx.map.find(fr.scope.node_id()) {
|
2014-01-17 06:23:09 -06:00
|
|
|
Some(ast_map::NodeBlock(ref blk)) => {
|
2014-08-27 20:46:52 -05:00
|
|
|
let (msg, opt_span) = explain_span(cx, "block", blk.span);
|
|
|
|
(format!("{} {}", prefix, msg), opt_span)
|
2012-07-31 23:08:24 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
Some(ast_map::NodeItem(it)) => {
|
|
|
|
let tag = item_scope_tag(&*it);
|
|
|
|
let (msg, opt_span) = explain_span(cx, tag, it.span);
|
|
|
|
(format!("{} {}", prefix, msg), opt_span)
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(_) | None => {
|
2014-08-27 20:46:52 -05:00
|
|
|
// this really should not happen
|
2014-11-18 07:22:59 -06:00
|
|
|
(format!("{} unknown free region bounded by scope {}", prefix, fr.scope), 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
|
|
|
|
2014-05-06 18:37:32 -05:00
|
|
|
ReEarlyBound(_, _, _, name) => {
|
|
|
|
(format!("{}", token::get_name(name)), None)
|
|
|
|
}
|
|
|
|
|
2012-08-07 21:48:24 -05:00
|
|
|
// I believe these cases should not occur (except when debugging,
|
|
|
|
// perhaps)
|
2014-05-06 18:37:32 -05:00
|
|
|
ty::ReInfer(_) | ty::ReLateBound(..) => {
|
2014-10-15 01:25:34 -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-08-27 20:46:52 -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-06-21 05:39:03 -05:00
|
|
|
pub fn bound_region_ptr_to_string(cx: &ctxt, br: BoundRegion) -> String {
|
|
|
|
bound_region_to_string(cx, "", false, br)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
2012-08-20 18:53:33 -05:00
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
pub fn bound_region_to_string(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-10-07 22:04:45 -05:00
|
|
|
BrAnon(_) | BrFresh(_) | BrEnv => 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-06-21 05:39:03 -05:00
|
|
|
pub fn region_ptr_to_string(cx: &ctxt, region: Region) -> String {
|
|
|
|
region_to_string(cx, "&", true, region)
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
pub fn region_to_string(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
|
|
|
}
|
2014-06-21 05:39:03 -05:00
|
|
|
ty::ReLateBound(_, br) => bound_region_to_string(cx, prefix, space, br),
|
|
|
|
ty::ReFree(ref fr) => bound_region_to_string(cx, prefix, space, fr.bound_region),
|
2013-10-29 09:34:11 -05:00
|
|
|
ty::ReInfer(ReSkolemized(_, br)) => {
|
2014-06-21 05:39:03 -05:00
|
|
|
bound_region_to_string(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-06-21 05:39:03 -05:00
|
|
|
pub fn mutability_to_string(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-09-29 14:11:30 -05:00
|
|
|
pub fn mt_to_string<'tcx>(cx: &ctxt<'tcx>, m: &mt<'tcx>) -> String {
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
format!("{}{}",
|
|
|
|
mutability_to_string(m.mutbl),
|
2014-10-29 15:20:06 -05:00
|
|
|
ty_to_string(cx, m.ty))
|
2012-04-13 15:35:57 -05:00
|
|
|
}
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
pub fn trait_store_to_string(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-06-21 05:39:03 -05:00
|
|
|
format!("{}{}", region_ptr_to_string(cx, r), mutability_to_string(m))
|
2013-04-02 00:32:37 -05:00
|
|
|
}
|
2012-07-13 17:24:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 13:56:00 -06:00
|
|
|
pub fn vec_map_to_string<T, F>(ts: &[T], f: F) -> String where
|
|
|
|
F: FnMut(&T) -> String,
|
|
|
|
{
|
2014-05-22 18:57:53 -05:00
|
|
|
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-09-29 14:11:30 -05:00
|
|
|
pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
|
|
|
|
fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
|
2014-12-09 09:36:46 -06:00
|
|
|
unsafety: ast::Unsafety,
|
2014-09-29 14:11:30 -05:00
|
|
|
abi: abi::Abi,
|
|
|
|
ident: Option<ast::Ident>,
|
2014-12-12 10:28:35 -06:00
|
|
|
sig: &ty::PolyFnSig<'tcx>)
|
2014-09-29 14:11:30 -05:00
|
|
|
-> String {
|
2014-05-22 18:57:53 -05:00
|
|
|
let mut s = String::new();
|
2014-12-09 09:36:46 -06:00
|
|
|
match unsafety {
|
|
|
|
ast::Unsafety::Normal => {}
|
|
|
|
ast::Unsafety::Unsafe => {
|
|
|
|
s.push_str(unsafety.to_string().as_slice());
|
2014-10-15 01:05:01 -05:00
|
|
|
s.push(' ');
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
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-12-10 21:46:38 -06:00
|
|
|
s.push_str(format!("extern {} ", abi.to_string())[]);
|
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) => {
|
2014-10-15 01:05:01 -05:00
|
|
|
s.push(' ');
|
2014-02-13 23:07:09 -06:00
|
|
|
s.push_str(token::get_ident(i).get());
|
|
|
|
}
|
|
|
|
_ => { }
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
|
2014-10-29 15:20:06 -05:00
|
|
|
push_sig_to_string(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-09-29 14:11:30 -05:00
|
|
|
fn closure_to_string<'tcx>(cx: &ctxt<'tcx>, cty: &ty::ClosureTy<'tcx>) -> String {
|
2014-05-22 18:57:53 -05:00
|
|
|
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-12-10 21:46:38 -06:00
|
|
|
s.push_str(region_to_string(cx, "", true, region)[]);
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:36:46 -06:00
|
|
|
match cty.unsafety {
|
|
|
|
ast::Unsafety::Normal => {}
|
|
|
|
ast::Unsafety::Unsafe => {
|
|
|
|
s.push_str(cty.unsafety.to_string().as_slice());
|
2014-10-15 01:05:01 -05:00
|
|
|
s.push(' ');
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
};
|
2012-08-10 20:15:08 -05:00
|
|
|
|
2014-08-27 20:46:52 -05:00
|
|
|
let bounds_str = cty.bounds.user_string(cx);
|
|
|
|
|
2014-04-11 10:03:10 -05:00
|
|
|
match cty.store {
|
|
|
|
ty::UniqTraitStore => {
|
|
|
|
assert_eq!(cty.onceness, ast::Once);
|
|
|
|
s.push_str("proc");
|
2014-08-27 20:46:52 -05:00
|
|
|
push_sig_to_string(cx, &mut s, '(', ')', &cty.sig,
|
2014-12-10 21:46:38 -06:00
|
|
|
bounds_str[]);
|
2014-04-11 10:03:10 -05:00
|
|
|
}
|
|
|
|
ty::RegionTraitStore(..) => {
|
|
|
|
match cty.onceness {
|
|
|
|
ast::Many => {}
|
|
|
|
ast::Once => s.push_str("once ")
|
2013-10-28 17:22:49 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
push_sig_to_string(cx, &mut s, '|', '|', &cty.sig,
|
2014-12-10 21:46:38 -06:00
|
|
|
bounds_str[]);
|
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-10-15 01:05:01 -05:00
|
|
|
s
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
2014-04-02 18:54:22 -05:00
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
fn push_sig_to_string<'tcx>(cx: &ctxt<'tcx>,
|
|
|
|
s: &mut String,
|
|
|
|
bra: char,
|
|
|
|
ket: char,
|
2014-12-12 10:28:35 -06:00
|
|
|
sig: &ty::PolyFnSig<'tcx>,
|
2014-09-29 14:11:30 -05:00
|
|
|
bounds: &str) {
|
2014-10-15 01:05:01 -05:00
|
|
|
s.push(bra);
|
2014-12-12 10:28:35 -06:00
|
|
|
let strs = sig.0.inputs
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
.iter()
|
2014-10-29 15:20:06 -05:00
|
|
|
.map(|a| ty_to_string(cx, *a))
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
.collect::<Vec<_>>();
|
2014-05-19 19:23:26 -05:00
|
|
|
s.push_str(strs.connect(", ").as_slice());
|
2014-12-12 10:28:35 -06:00
|
|
|
if sig.0.variadic {
|
2013-10-25 00:56:34 -05:00
|
|
|
s.push_str(", ...");
|
|
|
|
}
|
2014-10-15 01:05:01 -05:00
|
|
|
s.push(ket);
|
2013-10-25 00:56:34 -05:00
|
|
|
|
2014-08-27 20:46:52 -05:00
|
|
|
if !bounds.is_empty() {
|
|
|
|
s.push_str(":");
|
|
|
|
s.push_str(bounds);
|
|
|
|
}
|
|
|
|
|
2014-12-12 10:28:35 -06:00
|
|
|
match sig.0.output {
|
2014-10-24 14:14:37 -05:00
|
|
|
ty::FnConverging(t) => {
|
|
|
|
if !ty::type_is_nil(t) {
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
s.push_str(" -> ");
|
2014-12-10 21:46:38 -06:00
|
|
|
s.push_str(ty_to_string(cx, t)[]);
|
2014-10-24 14:14:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ty::FnDiverging => {
|
|
|
|
s.push_str(" -> !");
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-10 12:28:35 -06:00
|
|
|
|
2014-10-29 15:20:06 -05:00
|
|
|
fn infer_ty_to_string(cx: &ctxt, ty: ty::InferTy) -> String {
|
|
|
|
let print_var_ids = cx.sess.verbose();
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
match ty {
|
2014-11-05 04:36:53 -06:00
|
|
|
ty::TyVar(ref vid) if print_var_ids => vid.repr(cx),
|
|
|
|
ty::IntVar(ref vid) if print_var_ids => vid.repr(cx),
|
|
|
|
ty::FloatVar(ref vid) if print_var_ids => vid.repr(cx),
|
|
|
|
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => format!("_"),
|
2014-12-12 05:13:42 -06:00
|
|
|
ty::FreshTy(v) => format!("FreshTy({})", v),
|
|
|
|
ty::FreshIntTy(v) => format!("FreshIntTy({})", v)
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-10 12:28:35 -06:00
|
|
|
|
|
|
|
// pretty print the structural type representation:
|
2014-09-29 14:11:30 -05:00
|
|
|
match typ.sty {
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
ty_bool => "bool".to_string(),
|
|
|
|
ty_char => "char".to_string(),
|
|
|
|
ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
|
|
|
|
ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
|
|
|
|
ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
|
2014-10-29 15:20:06 -05:00
|
|
|
ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
ty_ptr(ref tm) => {
|
|
|
|
format!("*{} {}", match tm.mutbl {
|
|
|
|
ast::MutMutable => "mut",
|
|
|
|
ast::MutImmutable => "const",
|
|
|
|
}, ty_to_string(cx, tm.ty))
|
|
|
|
}
|
|
|
|
ty_rptr(r, ref tm) => {
|
|
|
|
let mut buf = region_ptr_to_string(cx, r);
|
2014-12-10 21:46:38 -06:00
|
|
|
buf.push_str(mt_to_string(cx, tm)[]);
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
buf
|
|
|
|
}
|
|
|
|
ty_open(typ) =>
|
2014-10-29 15:20:06 -05:00
|
|
|
format!("opened<{}>", ty_to_string(cx, typ)),
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
ty_tup(ref elems) => {
|
|
|
|
let strs = elems
|
|
|
|
.iter()
|
2014-10-29 15:20:06 -05:00
|
|
|
.map(|elem| ty_to_string(cx, *elem))
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
.collect::<Vec<_>>();
|
2014-12-10 21:46:38 -06:00
|
|
|
match strs[] {
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
[ref string] => format!("({},)", string),
|
|
|
|
strs => format!("({})", strs.connect(", "))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ty_closure(ref f) => {
|
2014-10-29 15:20:06 -05:00
|
|
|
closure_to_string(cx, &**f)
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
}
|
|
|
|
ty_bare_fn(ref f) => {
|
2014-12-09 09:36:46 -06:00
|
|
|
bare_fn_to_string(cx, f.unsafety, f.abi, None, &f.sig)
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
}
|
2014-10-29 15:20:06 -05:00
|
|
|
ty_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
ty_err => "[type error]".to_string(),
|
2014-10-31 05:36:07 -05:00
|
|
|
ty_param(ref param_ty) => {
|
|
|
|
if cx.sess.verbose() {
|
|
|
|
param_ty.repr(cx)
|
|
|
|
} else {
|
|
|
|
param_ty.user_string(cx)
|
|
|
|
}
|
|
|
|
}
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
|
|
|
|
let base = ty::item_path_str(cx, did);
|
|
|
|
let generics = ty::lookup_item_type(cx, did).generics;
|
2014-12-15 18:38:34 -06:00
|
|
|
parameterized(cx, base.as_slice(), substs, &generics, did)
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
}
|
|
|
|
ty_trait(box ty::TyTrait {
|
2014-11-07 05:16:57 -06:00
|
|
|
ref principal, ref bounds
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
}) => {
|
2014-12-11 12:37:37 -06:00
|
|
|
let principal = principal.user_string(cx);
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
let bound_str = bounds.user_string(cx);
|
2014-12-15 18:38:34 -06:00
|
|
|
let bound_sep = if bound_str.is_empty() { "" } else { " + " };
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
format!("{}{}{}",
|
2014-12-11 12:37:37 -06:00
|
|
|
principal,
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
bound_sep,
|
|
|
|
bound_str)
|
|
|
|
}
|
|
|
|
ty_str => "str".to_string(),
|
|
|
|
ty_unboxed_closure(ref did, _, ref substs) => {
|
|
|
|
let unboxed_closures = cx.unboxed_closures.borrow();
|
2014-11-06 11:25:16 -06:00
|
|
|
unboxed_closures.get(did).map(|cl| {
|
2014-10-29 15:20:06 -05:00
|
|
|
closure_to_string(cx, &cl.closure_type.subst(cx, substs))
|
2014-11-26 09:07:22 -06:00
|
|
|
}).unwrap_or_else(|| {
|
|
|
|
if did.krate == ast::LOCAL_CRATE {
|
|
|
|
let span = cx.map.span(did.node);
|
|
|
|
format!("closure[{}]", span.repr(cx))
|
|
|
|
} else {
|
|
|
|
format!("closure")
|
|
|
|
}
|
|
|
|
})
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
}
|
|
|
|
ty_vec(t, sz) => {
|
2014-10-29 15:20:06 -05:00
|
|
|
let inner_str = ty_to_string(cx, t);
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
match sz {
|
2014-12-19 20:20:51 -06:00
|
|
|
Some(n) => format!("[{}; {}]", inner_str, n),
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
None => format!("[{}]", inner_str),
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-05-06 18:37:32 -05:00
|
|
|
pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
|
|
|
|
-> &'static str {
|
|
|
|
match *category {
|
|
|
|
ty::StaticExplicitSelfCategory => "static",
|
|
|
|
ty::ByValueExplicitSelfCategory => "self",
|
|
|
|
ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
|
|
|
|
"&mut self"
|
|
|
|
}
|
|
|
|
ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
|
|
|
|
ty::ByBoxExplicitSelfCategory => "Box<self>",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn parameterized<'tcx>(cx: &ctxt<'tcx>,
|
|
|
|
base: &str,
|
|
|
|
substs: &subst::Substs<'tcx>,
|
2014-12-15 18:38:34 -06:00
|
|
|
generics: &ty::Generics<'tcx>,
|
|
|
|
did: ast::DefId)
|
2014-09-29 14:11:30 -05:00
|
|
|
-> String
|
2014-05-31 17:53:13 -05:00
|
|
|
{
|
2014-10-31 05:36:07 -05:00
|
|
|
if cx.sess.verbose() {
|
|
|
|
if substs.is_noop() {
|
|
|
|
return format!("{}", base);
|
|
|
|
} else {
|
|
|
|
return format!("{}<{},{}>",
|
|
|
|
base,
|
|
|
|
substs.regions.repr(cx),
|
|
|
|
substs.types.repr(cx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-06-21 05:39:03 -05:00
|
|
|
let s = region_to_string(cx, "", false, r);
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
if s.is_empty() {
|
2014-05-31 17:53:13 -05:00
|
|
|
// 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!("'_"));
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -05:00
|
|
|
} else {
|
|
|
|
strs.push(s)
|
2014-05-31 17:53:13 -05:00
|
|
|
}
|
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-07-04 09:39:28 -05:00
|
|
|
let tps = substs.types.get_slice(subst::TypeSpace);
|
|
|
|
let ty_params = generics.types.get_slice(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-10-31 05:36:07 -05:00
|
|
|
let num_defaults = if has_defaults {
|
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
|
|
|
|
2014-09-24 06:41:09 -05:00
|
|
|
for t in tps[..tps.len() - num_defaults].iter() {
|
2014-10-29 15:20:06 -05:00
|
|
|
strs.push(ty_to_string(cx, *t))
|
2013-06-25 20:25:27 -05:00
|
|
|
}
|
2013-06-17 18:49:45 -05:00
|
|
|
|
2014-12-15 18:38:34 -06:00
|
|
|
if cx.lang_items.fn_trait_kind(did).is_some() {
|
|
|
|
format!("{}({}){}",
|
|
|
|
base,
|
2014-12-18 06:10:41 -06:00
|
|
|
if strs[0].starts_with("(") && strs[0].ends_with(",)") {
|
|
|
|
strs[0][1 .. strs[0].len() - 2] // Remove '(' and ',)'
|
2014-12-21 02:12:56 -06:00
|
|
|
} else if strs[0].starts_with("(") && strs[0].ends_with(")") {
|
|
|
|
strs[0][1 .. strs[0].len() - 1] // Remove '(' and ')'
|
2014-12-18 06:10:41 -06:00
|
|
|
} else {
|
|
|
|
strs[0][]
|
|
|
|
},
|
2014-12-15 18:38:34 -06:00
|
|
|
if &*strs[1] == "()" { String::new() } else { format!(" -> {}", strs[1]) })
|
|
|
|
} else if strs.len() > 0 {
|
Improve the readability of diagnostics that involve unresolved type variables
Diagnostics such as the following
```
mismatched types: expected `core::result::Result<uint,()>`, found `core::option::Option<<generic #1>>`
<anon>:6 let a: Result<uint, ()> = None;
^~~~
mismatched types: expected `&mut <generic #2>`, found `uint`
<anon>:7 f(42u);
^~~
```
tend to be fairly unappealing to new users. While specific type var IDs are valuable in
diagnostics that deal with more than one such variable, in practice many messages
only mention one. In those cases, leaving out the specific number makes the messages
slightly less terrifying.
In addition, type variables have been changed to use the type hole syntax `_` in diagnostics.
With a variable ID, they're printed as `_#id` (e.g. `_#1`). In cases where the ID is left out,
it's simply `_`. Integer and float variables have an additional suffix after the number, e.g.
`_#1i` or `_#3f`.
2014-10-23 15:35:19 -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-09-29 14:11:30 -05:00
|
|
|
pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> 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-12-10 21:46:38 -06:00
|
|
|
s = s[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
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Option<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> 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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for P<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-10-31 04:44:10 -05:00
|
|
|
(*self).repr(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx,T:Repr<'tcx>,U:Repr<'tcx>> Repr<'tcx> for Result<T,U> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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-09-29 14:11:30 -05:00
|
|
|
impl<'a, 'tcx, Sized? T:Repr<'tcx>> Repr<'tcx> for &'a T {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-11-17 14:40:05 -06:00
|
|
|
Repr::repr(*self, tcx)
|
2014-04-21 18:21:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Rc<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-09-12 11:09:17 -05:00
|
|
|
(&**self).repr(tcx)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Box<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> 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-09-29 14:11:30 -05:00
|
|
|
fn repr_vec<'tcx, T:Repr<'tcx>>(tcx: &ctxt<'tcx>, v: &[T]) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
vec_map_to_string(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
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for [T] {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-11-17 14:40:05 -06:00
|
|
|
repr_vec(tcx, self)
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for OwnedSlice<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-10 21:46:38 -06:00
|
|
|
repr_vec(tcx, self[])
|
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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Vec<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-10 21:46:38 -06:00
|
|
|
repr_vec(tcx, self[])
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:UserString<'tcx>> UserString<'tcx> for Vec<T> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-08-27 20:46:52 -05:00
|
|
|
let strs: Vec<String> =
|
|
|
|
self.iter().map(|t| t.user_string(tcx)).collect();
|
|
|
|
strs.connect(", ")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for def::Def {
|
2014-05-31 17:53:13 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-05-31 17:53:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::TypeParameterDef<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-08-05 21:44:21 -05:00
|
|
|
format!("TypeParameterDef({}, {}, {}/{})",
|
|
|
|
self.def_id,
|
|
|
|
self.bounds.repr(tcx),
|
|
|
|
self.space,
|
|
|
|
self.index)
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::RegionParameterDef {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
format!("RegionParameterDef(name={}, def_id={}, bounds={})",
|
2014-05-27 22:44:58 -05:00
|
|
|
token::get_name(self.name),
|
2014-08-27 20:46:52 -05:00
|
|
|
self.def_id.repr(tcx),
|
|
|
|
self.bounds.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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::TyS<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
ty_to_string(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::mt<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
mt_to_string(tcx, self)
|
2014-06-20 05:35:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for subst::Substs<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-05-31 17:53:13 -05:00
|
|
|
format!("Substs[types={}, regions={}]",
|
|
|
|
self.types.repr(tcx),
|
|
|
|
self.regions.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for subst::VecPerParamSpace<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-10-29 20:29:16 -05:00
|
|
|
format!("[{};{};{};{}]",
|
|
|
|
self.get_slice(subst::TypeSpace).repr(tcx),
|
|
|
|
self.get_slice(subst::SelfSpace).repr(tcx),
|
|
|
|
self.get_slice(subst::AssocSpace).repr(tcx),
|
|
|
|
self.get_slice(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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::ItemSubsts<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("ItemSubsts({})", self.substs.repr(tcx))
|
2014-05-07 06:20:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::BuiltinBounds {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut res = Vec::new();
|
2014-08-27 20:46:52 -05:00
|
|
|
for b in self.iter() {
|
2013-05-07 16:30:21 -05:00
|
|
|
res.push(match b {
|
2014-10-15 01:05:01 -05:00
|
|
|
ty::BoundSend => "Send".to_string(),
|
|
|
|
ty::BoundSized => "Sized".to_string(),
|
|
|
|
ty::BoundCopy => "Copy".to_string(),
|
|
|
|
ty::BoundSync => "Sync".to_string(),
|
2013-05-07 16:30:21 -05:00
|
|
|
});
|
2013-07-25 23:53:29 -05:00
|
|
|
}
|
2014-08-27 20:46:52 -05:00
|
|
|
res.connect("+")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::ExistentialBounds {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
self.user_string(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::ParamBounds<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-08-27 20:46:52 -05:00
|
|
|
let mut res = Vec::new();
|
|
|
|
res.push(self.builtin_bounds.repr(tcx));
|
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-06-26 01:15:14 -05:00
|
|
|
res.connect("+")
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::TraitRef<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-11-15 16:25:05 -06:00
|
|
|
// when printing out the debug representation, we don't need
|
|
|
|
// to enumerate the `for<...>` etc because the debruijn index
|
|
|
|
// tells you everything you need to know.
|
2014-09-12 11:09:17 -05:00
|
|
|
let base = ty::item_path_str(tcx, self.def_id);
|
|
|
|
let trait_def = ty::lookup_trait_def(tcx, self.def_id);
|
2014-12-11 12:37:37 -06:00
|
|
|
format!("TraitRef({}, {})",
|
2014-09-12 11:09:17 -05:00
|
|
|
self.substs.self_ty().repr(tcx),
|
2014-12-15 18:38:34 -06:00
|
|
|
parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::TraitDef<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-08-27 20:46:52 -05:00
|
|
|
format!("TraitDef(generics={}, bounds={}, trait_ref={})",
|
|
|
|
self.generics.repr(tcx),
|
|
|
|
self.bounds.repr(tcx),
|
|
|
|
self.trait_ref.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::TraitItem {
|
2014-10-31 05:36:07 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
match *self {
|
|
|
|
ast::RequiredMethod(ref data) => format!("RequiredMethod({}, id={})",
|
|
|
|
data.ident, data.id),
|
|
|
|
ast::ProvidedMethod(ref data) => format!("ProvidedMethod(id={})",
|
|
|
|
data.id),
|
|
|
|
ast::TypeTraitItem(ref data) => format!("TypeTraitItem({}, id={})",
|
|
|
|
data.ty_param.ident, data.ty_param.id),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Expr {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
format!("expr({}: {})", self.id, pprust::expr_to_string(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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Path {
|
2014-05-31 17:53:13 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
format!("path({})", pprust::path_to_string(self))
|
2014-05-31 17:53:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for ast::Path {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn user_string(&self, _tcx: &ctxt) -> String {
|
|
|
|
pprust::path_to_string(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Ty {
|
2014-10-31 05:36:07 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("type({})", pprust::ty_to_string(self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Item {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
format!("item({})", tcx.map.node_to_string(self.id))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Lifetime {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("lifetime({}: {})", self.id, pprust::lifetime_to_string(self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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),
|
2014-06-21 05:39:03 -05:00
|
|
|
pprust::stmt_to_string(self))
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Pat {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
format!("pat({}: {})", self.id, pprust::pat_to_string(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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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),
|
2014-10-07 22:04:45 -05:00
|
|
|
ty::BrEnv => "BrEnv".to_string()
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
2013-05-23 20:37:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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
|
|
|
}
|
|
|
|
|
2014-08-27 20:46:52 -05:00
|
|
|
ty::ReFree(ref fr) => fr.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-11-05 04:36:53 -06:00
|
|
|
format!("{}", vid)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for ty::Region {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
|
|
|
region_to_string(tcx, "", false, *self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::FreeRegion {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
|
|
|
format!("ReFree({}, {})",
|
2014-11-18 07:22:59 -06:00
|
|
|
self.scope.node_id(),
|
2014-08-27 20:46:52 -05:00
|
|
|
self.bound_region.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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 {
|
2014-09-07 12:09:06 -05:00
|
|
|
match tcx.map.find(self.node) {
|
|
|
|
Some(ast_map::NodeItem(..)) |
|
|
|
|
Some(ast_map::NodeForeignItem(..)) |
|
|
|
|
Some(ast_map::NodeImplItem(..)) |
|
|
|
|
Some(ast_map::NodeTraitItem(..)) |
|
|
|
|
Some(ast_map::NodeVariant(..)) |
|
|
|
|
Some(ast_map::NodeStructCtor(..)) => {
|
|
|
|
return format!(
|
2014-10-15 01:25:34 -05:00
|
|
|
"{}:{}",
|
2014-05-09 20:45:36 -05:00
|
|
|
*self,
|
|
|
|
ty::item_path_str(tcx, *self))
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
}
|
2014-09-07 12:09:06 -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
|
|
|
}
|
|
|
|
}
|
2014-10-15 01:25:34 -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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::Polytype<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> 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
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::Generics<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-07 10:10:48 -06:00
|
|
|
format!("Generics(types: {}, regions: {}, predicates: {})",
|
2014-05-31 17:53:13 -05:00
|
|
|
self.types.repr(tcx),
|
2014-12-07 10:10:48 -06:00
|
|
|
self.regions.repr(tcx),
|
|
|
|
self.predicates.repr(tcx))
|
2013-10-29 05:03:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::GenericBounds<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-07 10:10:48 -06:00
|
|
|
format!("GenericBounds({})",
|
|
|
|
self.predicates.repr(tcx))
|
2014-11-15 16:25:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::Variance {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
// The first `.to_string()` returns a &'static str (it is not an implementation
|
|
|
|
// of the ToString trait). Because of that, we need to call `.to_string()` again
|
2014-06-05 02:15:19 -05:00
|
|
|
// if we want to have a `String`.
|
2014-09-22 19:38:49 -05:00
|
|
|
let result: &'static str = (*self).to_string();
|
|
|
|
result.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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::Method<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-09-30 19:11:34 -05:00
|
|
|
format!("method(name: {}, generics: {}, fty: {}, \
|
2014-05-27 22:44:58 -05:00
|
|
|
explicit_self: {}, vis: {}, def_id: {})",
|
2014-09-30 19:11:34 -05:00
|
|
|
self.name.repr(tcx),
|
2014-05-27 22:44:58 -05:00
|
|
|
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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for ast::Name {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn user_string(&self, _tcx: &ctxt) -> String {
|
|
|
|
token::get_name(*self).get().to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::ExplicitSelf_ {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Visibility {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::BareFnTy<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-09 09:36:46 -06:00
|
|
|
format!("BareFnTy {{unsafety: {}, abi: {}, sig: {}}}",
|
|
|
|
self.unsafety,
|
2014-06-21 05:39:03 -05:00
|
|
|
self.abi.to_string(),
|
2014-05-28 11:24:28 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::FnSig<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-12 10:28:35 -06:00
|
|
|
format!("fn{} -> {}", self.inputs.repr(tcx), self.output.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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::FnOutput<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-10-24 14:14:37 -05:00
|
|
|
match *self {
|
2014-10-28 12:32:05 -05:00
|
|
|
ty::FnConverging(ty) =>
|
|
|
|
format!("FnConverging({0})", ty.repr(tcx)),
|
|
|
|
ty::FnDiverging =>
|
|
|
|
"FnDiverging".to_string()
|
2014-10-24 14:14:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 13:21:20 -06:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::MethodCallee<'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-05-28 11:24:28 -05:00
|
|
|
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-11-25 13:21:20 -06:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::MethodOrigin<'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> 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-11-25 13:21:20 -06:00
|
|
|
&ty::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-11-25 13:21:20 -06:00
|
|
|
&ty::MethodStaticUnboxedClosure(def_id) => {
|
2014-05-29 00:26:56 -05:00
|
|
|
format!("MethodStaticUnboxedClosure({})", def_id.repr(tcx))
|
|
|
|
}
|
2014-11-25 13:21:20 -06:00
|
|
|
&ty::MethodTypeParam(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-11-25 13:21:20 -06:00
|
|
|
&ty::MethodTraitObject(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-11-25 13:21:20 -06:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::MethodParam<'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-09-12 11:09:17 -05:00
|
|
|
format!("MethodParam({},{})",
|
|
|
|
self.trait_ref.repr(tcx),
|
|
|
|
self.method_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-11-25 13:21:20 -06:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::MethodObject<'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("MethodObject({},{},{})",
|
2014-09-12 11:09:17 -05:00
|
|
|
self.trait_ref.repr(tcx),
|
2014-05-27 22:44:58 -05:00
|
|
|
self.method_num,
|
|
|
|
self.real_index)
|
2013-08-13 15:22:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::TraitStore {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
trait_store_to_string(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::BuiltinBound {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> 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-10-15 01:05:01 -05:00
|
|
|
ty::BoundSend => "Send".to_string(),
|
|
|
|
ty::BoundSized => "Sized".to_string(),
|
|
|
|
ty::BoundCopy => "Copy".to_string(),
|
|
|
|
ty::BoundSync => "Sync".to_string(),
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for Span {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
tcx.sess.codemap().span_to_string(*self).to_string()
|
2013-05-23 20:37:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, A:UserString<'tcx>> UserString<'tcx> for Rc<A> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
2013-05-23 20:37:37 -05:00
|
|
|
let this: &A = &**self;
|
|
|
|
this.user_string(tcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for ty::ParamBounds<'tcx> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-08-27 20:46:52 -05:00
|
|
|
let mut result = Vec::new();
|
|
|
|
let s = self.builtin_bounds.user_string(tcx);
|
|
|
|
if !s.is_empty() {
|
|
|
|
result.push(s);
|
|
|
|
}
|
|
|
|
for n in self.trait_bounds.iter() {
|
|
|
|
result.push(n.user_string(tcx));
|
|
|
|
}
|
2014-12-15 18:38:34 -06:00
|
|
|
result.connect(" + ")
|
2014-08-27 20:46:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for ty::ExistentialBounds {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
2014-11-06 11:25:16 -06:00
|
|
|
if self.builtin_bounds.contains(&ty::BoundSend) &&
|
2014-08-27 20:46:52 -05:00
|
|
|
self.region_bound == ty::ReStatic
|
|
|
|
{ // Region bound is implied by builtin bounds:
|
|
|
|
return self.builtin_bounds.repr(tcx);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::new();
|
|
|
|
|
|
|
|
let region_str = self.region_bound.user_string(tcx);
|
|
|
|
if !region_str.is_empty() {
|
|
|
|
res.push(region_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
for bound in self.builtin_bounds.iter() {
|
|
|
|
res.push(bound.user_string(tcx));
|
|
|
|
}
|
|
|
|
|
|
|
|
res.connect("+")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 10:28:35 -06:00
|
|
|
impl<'tcx, T> UserString<'tcx> for ty::Binder<T>
|
|
|
|
where T : UserString<'tcx> + TypeFoldable<'tcx>
|
|
|
|
{
|
2014-09-29 14:11:30 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-11-15 16:25:05 -06:00
|
|
|
// Replace any anonymous late-bound regions with named
|
|
|
|
// variants, using gensym'd identifiers, so that we can
|
|
|
|
// clearly differentiate between named and unnamed regions in
|
|
|
|
// the output. We'll probably want to tweak this over time to
|
|
|
|
// decide just how much information to give.
|
|
|
|
let mut names = Vec::new();
|
2014-12-12 10:28:35 -06:00
|
|
|
let (unbound_value, _) = ty::replace_late_bound_regions(tcx, self, |br, debruijn| {
|
2014-11-15 16:25:05 -06:00
|
|
|
ty::ReLateBound(debruijn, match br {
|
|
|
|
ty::BrNamed(_, name) => {
|
|
|
|
names.push(token::get_name(name));
|
|
|
|
br
|
|
|
|
}
|
|
|
|
ty::BrAnon(_) |
|
|
|
|
ty::BrFresh(_) |
|
|
|
|
ty::BrEnv => {
|
2014-12-11 12:37:37 -06:00
|
|
|
let name = token::gensym("'r");
|
2014-11-15 16:25:05 -06:00
|
|
|
names.push(token::get_name(name));
|
|
|
|
ty::BrNamed(ast_util::local_def(ast::DUMMY_NODE_ID), name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
let names: Vec<_> = names.iter().map(|s| s.get()).collect();
|
|
|
|
|
2014-12-12 10:28:35 -06:00
|
|
|
let value_str = unbound_value.user_string(tcx);
|
2014-12-11 12:37:37 -06:00
|
|
|
if names.len() == 0 {
|
2014-12-12 10:28:35 -06:00
|
|
|
value_str
|
2014-12-11 12:37:37 -06:00
|
|
|
} else {
|
2014-12-12 10:28:35 -06:00
|
|
|
format!("for<{}> {}", names.connect(","), value_str)
|
2014-12-11 12:37:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-15 16:25:05 -06:00
|
|
|
|
2014-12-11 12:37:37 -06:00
|
|
|
impl<'tcx> UserString<'tcx> for ty::TraitRef<'tcx> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
let path_str = 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);
|
2014-12-11 12:37:37 -06:00
|
|
|
parameterized(tcx, path_str.as_slice(), &self.substs,
|
|
|
|
&trait_def.generics, self.def_id)
|
2013-05-07 16:30:21 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-22 05:54:35 -05:00
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for Ty<'tcx> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
ty_to_string(tcx, *self)
|
2013-05-22 05:54:35 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> 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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for abi::Abi {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
self.to_string()
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for abi::Abi {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn user_string(&self, _tcx: &ctxt) -> String {
|
2014-06-21 05:39:03 -05:00
|
|
|
self.to_string()
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-07 13:51:18 -06:00
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::Mutability {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::BorrowKind {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-02-07 13:51:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> 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
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::IntVid {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::FloatVid {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::RegionVid {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::TyVid {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
|
|
|
format!("{}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::IntVarValue {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-06-20 05:35:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::IntTy {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-06-20 05:35:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::UintTy {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-06-20 05:35:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ast::FloatTy {
|
2014-06-20 05:35:06 -05:00
|
|
|
fn repr(&self, _tcx: &ctxt) -> String {
|
2014-10-15 01:25:34 -05:00
|
|
|
format!("{}", *self)
|
2014-06-20 05:35:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::ExplicitSelfCategory {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, _: &ctxt) -> String {
|
|
|
|
explicit_self_category_to_str(self).to_string()
|
2014-06-20 05:35:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> UserString<'tcx> for ParamTy {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn user_string(&self, tcx: &ctxt) -> String {
|
|
|
|
let id = self.idx;
|
|
|
|
let did = self.def_id;
|
2014-11-06 11:25:16 -06:00
|
|
|
let ident = match tcx.ty_param_defs.borrow().get(&did.node) {
|
2014-09-30 19:11:34 -05:00
|
|
|
Some(def) => token::get_name(def.name).get().to_string(),
|
2014-08-27 20:46:52 -05:00
|
|
|
|
|
|
|
// This can only happen when a type mismatch error happens and
|
|
|
|
// the actual type has more type parameters than the expected one.
|
|
|
|
None => format!("<generic #{}>", id),
|
|
|
|
};
|
|
|
|
ident
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ParamTy {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn repr(&self, tcx: &ctxt) -> String {
|
2014-10-31 05:36:07 -05:00
|
|
|
let ident = self.user_string(tcx);
|
|
|
|
format!("{}/{}.{}", ident, self.space, self.idx)
|
2014-05-06 18:37:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, A:Repr<'tcx>, B:Repr<'tcx>> Repr<'tcx> for (A,B) {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-08-27 20:46:52 -05:00
|
|
|
let &(ref a, ref b) = self;
|
|
|
|
format!("({},{})", a.repr(tcx), b.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 11:09:17 -05:00
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for ty::Binder<T> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
2014-12-12 10:28:35 -06:00
|
|
|
format!("Binder({})", self.0.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, S, H, K, V> Repr<'tcx> for HashMap<K,V,H>
|
|
|
|
where K : Hash<S> + Eq + Repr<'tcx>,
|
|
|
|
V : Repr<'tcx>,
|
|
|
|
H : Hasher<S>
|
|
|
|
{
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
format!("HashMap({})",
|
|
|
|
self.iter()
|
|
|
|
.map(|(k,v)| format!("{} => {}", k.repr(tcx), v.repr(tcx)))
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
.connect(", "))
|
2014-11-15 15:47:59 -06:00
|
|
|
}
|
|
|
|
}
|
2014-12-13 04:34:34 -06:00
|
|
|
|
|
|
|
impl<'tcx, T, U> Repr<'tcx> for ty::OutlivesPredicate<T,U>
|
|
|
|
where T : Repr<'tcx> + TypeFoldable<'tcx>,
|
|
|
|
U : Repr<'tcx> + TypeFoldable<'tcx>,
|
|
|
|
{
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
format!("OutlivesPredicate({}, {})",
|
|
|
|
self.0.repr(tcx),
|
|
|
|
self.1.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T, U> UserString<'tcx> for ty::OutlivesPredicate<T,U>
|
|
|
|
where T : UserString<'tcx> + TypeFoldable<'tcx>,
|
|
|
|
U : UserString<'tcx> + TypeFoldable<'tcx>,
|
|
|
|
{
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
format!("{} : {}",
|
|
|
|
self.0.user_string(tcx),
|
|
|
|
self.1.user_string(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> Repr<'tcx> for ty::EquatePredicate<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
format!("EquatePredicate({}, {})",
|
|
|
|
self.0.repr(tcx),
|
|
|
|
self.1.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> UserString<'tcx> for ty::EquatePredicate<'tcx> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
format!("{} == {}",
|
|
|
|
self.0.user_string(tcx),
|
|
|
|
self.1.user_string(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> UserString<'tcx> for ty::Predicate<'tcx> {
|
|
|
|
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
|
|
|
|
match *self {
|
|
|
|
ty::Predicate::Trait(ref trait_ref) => {
|
|
|
|
format!("{} : {}",
|
|
|
|
trait_ref.self_ty().user_string(tcx),
|
|
|
|
trait_ref.user_string(tcx))
|
|
|
|
}
|
|
|
|
ty::Predicate::Equate(ref predicate) => predicate.user_string(tcx),
|
|
|
|
ty::Predicate::RegionOutlives(ref predicate) => predicate.user_string(tcx),
|
|
|
|
ty::Predicate::TypeOutlives(ref predicate) => predicate.user_string(tcx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|