Skip to content

Commit 852f58c

Browse files
committed
---
yaml --- r: 213970 b: refs/heads/master c: 96ad4a4 h: refs/heads/master v: v3
1 parent 9ea24e3 commit 852f58c

File tree

29 files changed

+134
-153
lines changed

29 files changed

+134
-153
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4e0cb86a5c173096b08819af37f57970ac332561
2+
refs/heads/master: 96ad4a486381497da00ad12413bfc0fbac201189
33
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/librustc/middle/astencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use middle::privacy::{AllPublic, LastMod};
3131
use middle::subst;
3232
use middle::subst::VecPerParamSpace;
3333
use middle::ty::{self, Ty, MethodCall, MethodCallee, MethodOrigin};
34-
use util::ppaux::ty_to_string;
34+
use util::ppaux::Repr;
3535

3636
use syntax::{ast, ast_util, codemap, fold};
3737
use syntax::codemap::Span;
@@ -1624,7 +1624,7 @@ fn decode_side_tables(dcx: &DecodeContext,
16241624
c::tag_table_node_type => {
16251625
let ty = val_dsr.read_ty(dcx);
16261626
debug!("inserting ty for node {}: {}",
1627-
id, ty_to_string(dcx.tcx, ty));
1627+
id, ty.repr(dcx.tcx));
16281628
dcx.tcx.node_type_insert(id, ty);
16291629
}
16301630
c::tag_table_item_subst => {

trunk/src/librustc/middle/check_match.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use syntax::print::pprust::pat_to_string;
3636
use syntax::parse::token;
3737
use syntax::ptr::P;
3838
use syntax::visit::{self, Visitor, FnKind};
39-
use util::ppaux::ty_to_string;
39+
use util::ppaux::UserString;
4040
use util::nodemap::FnvHashMap;
4141

4242
pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
@@ -209,9 +209,8 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
209209
if !type_is_empty(cx.tcx, pat_ty) {
210210
// We know the type is inhabited, so this must be wrong
211211
span_err!(cx.tcx.sess, ex.span, E0002,
212-
"non-exhaustive patterns: type {} is non-empty",
213-
ty_to_string(cx.tcx, pat_ty)
214-
);
212+
"non-exhaustive patterns: type {} is non-empty",
213+
pat_ty.user_string(cx.tcx));
215214
}
216215
// If the type *is* empty, it's vacuously exhaustive
217216
return;
@@ -244,11 +243,11 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
244243
span_warn!(cx.tcx.sess, p.span, E0170,
245244
"pattern binding `{}` is named the same as one \
246245
of the variants of the type `{}`",
247-
&token::get_ident(ident.node), ty_to_string(cx.tcx, pat_ty));
246+
&token::get_ident(ident.node), pat_ty.user_string(cx.tcx));
248247
fileline_help!(cx.tcx.sess, p.span,
249248
"if you meant to match on a variant, \
250249
consider making the path in the pattern qualified: `{}::{}`",
251-
ty_to_string(cx.tcx, pat_ty), &token::get_ident(ident.node));
250+
pat_ty.user_string(cx.tcx), &token::get_ident(ident.node));
252251
}
253252
}
254253
}

trunk/src/librustc/middle/check_rvalues.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use middle::expr_use_visitor as euv;
1515
use middle::mem_categorization as mc;
1616
use middle::ty::ParameterEnvironment;
1717
use middle::ty;
18-
use util::ppaux::ty_to_string;
18+
use util::ppaux::{Repr, UserString};
1919

2020
use syntax::ast;
2121
use syntax::codemap::Span;
@@ -59,11 +59,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContextDelegate<'a, 'tcx> {
5959
span: Span,
6060
cmt: mc::cmt<'tcx>,
6161
_: euv::ConsumeMode) {
62-
debug!("consume; cmt: {:?}; type: {}", *cmt, ty_to_string(self.tcx, cmt.ty));
62+
debug!("consume; cmt: {:?}; type: {}", *cmt, cmt.ty.repr(self.tcx));
6363
if !ty::type_is_sized(Some(self.param_env), self.tcx, span, cmt.ty) {
6464
span_err!(self.tcx.sess, span, E0161,
6565
"cannot move a value of type {0}: the size of {0} cannot be statically determined",
66-
ty_to_string(self.tcx, cmt.ty));
66+
cmt.ty.user_string(self.tcx));
6767
}
6868
}
6969

trunk/src/librustc/middle/effect.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use self::UnsafeContext::*;
1515
use middle::def;
1616
use middle::ty::{self, Ty};
1717
use middle::ty::MethodCall;
18-
use util::ppaux;
18+
use util::ppaux::Repr;
1919

2020
use syntax::ast;
2121
use syntax::codemap::Span;
@@ -67,7 +67,7 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
6767
_ => return
6868
};
6969
debug!("effect: checking index with base type {}",
70-
ppaux::ty_to_string(self.tcx, base_type));
70+
base_type.repr(self.tcx));
7171
match base_type.sty {
7272
ty::TyBox(ty) | ty::TyRef(_, ty::mt{ty, ..}) => if ty::TyStr == ty.sty {
7373
span_err!(self.tcx.sess, e.span, E0134,
@@ -143,7 +143,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
143143
let method_call = MethodCall::expr(expr.id);
144144
let base_type = self.tcx.method_map.borrow().get(&method_call).unwrap().ty;
145145
debug!("effect: method call case, base type is {}",
146-
ppaux::ty_to_string(self.tcx, base_type));
146+
base_type.repr(self.tcx));
147147
if type_is_unsafe_function(base_type) {
148148
self.require_unsafe(expr.span,
149149
"invocation of unsafe method")
@@ -152,15 +152,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
152152
ast::ExprCall(ref base, _) => {
153153
let base_type = ty::node_id_to_type(self.tcx, base.id);
154154
debug!("effect: call case, base type is {}",
155-
ppaux::ty_to_string(self.tcx, base_type));
155+
base_type.repr(self.tcx));
156156
if type_is_unsafe_function(base_type) {
157157
self.require_unsafe(expr.span, "call to unsafe function")
158158
}
159159
}
160160
ast::ExprUnary(ast::UnDeref, ref base) => {
161161
let base_type = ty::node_id_to_type(self.tcx, base.id);
162162
debug!("effect: unary case, base type is {}",
163-
ppaux::ty_to_string(self.tcx, base_type));
163+
base_type.repr(self.tcx));
164164
if let ty::TyRawPtr(_) = base_type.sty {
165165
self.require_unsafe(expr.span, "dereference of raw pointer")
166166
}

trunk/src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use syntax::ast;
3636
use syntax::codemap;
3737
use syntax::codemap::Span;
3838
use util::nodemap::FnvHashMap;
39-
use util::ppaux::ty_to_string;
4039
use util::ppaux::{Repr, UserString};
4140

4241
use self::combine::CombineFields;
@@ -862,8 +861,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
862861
}
863862

864863
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
865-
ty_to_string(self.tcx,
866-
self.resolve_type_vars_if_possible(&t))
864+
self.resolve_type_vars_if_possible(&t).user_string(self.tcx)
867865
}
868866

869867
pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {

trunk/src/librustc/middle/ty.rs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use middle::ty;
6262
use middle::ty_fold::{self, TypeFoldable, TypeFolder};
6363
use middle::ty_walk::{self, TypeWalker};
6464
use util::ppaux::note_and_explain_region;
65-
use util::ppaux::ty_to_string;
6665
use util::ppaux::{Repr, UserString};
6766
use util::common::{memoized, ErrorReported};
6867
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
@@ -3568,7 +3567,7 @@ pub fn sequence_element_type<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
35683567
TyArray(ty, _) | TySlice(ty) => ty,
35693568
TyStr => mk_mach_uint(cx, ast::TyU8),
35703569
_ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}",
3571-
ty_to_string(cx, ty))),
3570+
ty.user_string(cx))),
35723571
}
35733572
}
35743573

@@ -4139,24 +4138,20 @@ pub fn is_ffi_safe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
41394138
pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool {
41404139
fn type_requires<'tcx>(cx: &ctxt<'tcx>, seen: &mut Vec<DefId>,
41414140
r_ty: Ty<'tcx>, ty: Ty<'tcx>) -> bool {
4142-
debug!("type_requires({:?}, {:?})?",
4143-
::util::ppaux::ty_to_string(cx, r_ty),
4144-
::util::ppaux::ty_to_string(cx, ty));
4141+
debug!("type_requires({}, {})?",
4142+
r_ty.repr(cx), ty.repr(cx));
41454143

41464144
let r = r_ty == ty || subtypes_require(cx, seen, r_ty, ty);
41474145

4148-
debug!("type_requires({:?}, {:?})? {:?}",
4149-
::util::ppaux::ty_to_string(cx, r_ty),
4150-
::util::ppaux::ty_to_string(cx, ty),
4151-
r);
4146+
debug!("type_requires({}, {})? {:?}",
4147+
r_ty.repr(cx), ty.repr(cx), r);
41524148
return r;
41534149
}
41544150

41554151
fn subtypes_require<'tcx>(cx: &ctxt<'tcx>, seen: &mut Vec<DefId>,
41564152
r_ty: Ty<'tcx>, ty: Ty<'tcx>) -> bool {
4157-
debug!("subtypes_require({:?}, {:?})?",
4158-
::util::ppaux::ty_to_string(cx, r_ty),
4159-
::util::ppaux::ty_to_string(cx, ty));
4153+
debug!("subtypes_require({}, {})?",
4154+
r_ty.repr(cx), ty.repr(cx));
41604155

41614156
let r = match ty.sty {
41624157
// fixed length vectors need special treatment compared to
@@ -4234,10 +4229,8 @@ pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool {
42344229
}
42354230
};
42364231

4237-
debug!("subtypes_require({:?}, {:?})? {:?}",
4238-
::util::ppaux::ty_to_string(cx, r_ty),
4239-
::util::ppaux::ty_to_string(cx, ty),
4240-
r);
4232+
debug!("subtypes_require({}, {})? {:?}",
4233+
r_ty.repr(cx), ty.repr(cx), r);
42414234

42424235
return r;
42434236
}
@@ -4343,8 +4336,7 @@ pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>)
43434336
fn is_type_structurally_recursive<'tcx>(cx: &ctxt<'tcx>, sp: Span,
43444337
seen: &mut Vec<Ty<'tcx>>,
43454338
ty: Ty<'tcx>) -> Representability {
4346-
debug!("is_type_structurally_recursive: {:?}",
4347-
::util::ppaux::ty_to_string(cx, ty));
4339+
debug!("is_type_structurally_recursive: {}", ty.repr(cx));
43484340

43494341
match ty.sty {
43504342
TyStruct(did, _) | TyEnum(did, _) => {
@@ -4363,9 +4355,9 @@ pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>)
43634355
match iter.next() {
43644356
Some(&seen_type) => {
43654357
if same_struct_or_enum_def_id(seen_type, did) {
4366-
debug!("SelfRecursive: {:?} contains {:?}",
4367-
::util::ppaux::ty_to_string(cx, seen_type),
4368-
::util::ppaux::ty_to_string(cx, ty));
4358+
debug!("SelfRecursive: {} contains {}",
4359+
seen_type.repr(cx),
4360+
ty.repr(cx));
43694361
return SelfRecursive;
43704362
}
43714363
}
@@ -4383,9 +4375,9 @@ pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>)
43834375

43844376
for &seen_type in iter {
43854377
if same_type(ty, seen_type) {
4386-
debug!("ContainsRecursive: {:?} contains {:?}",
4387-
::util::ppaux::ty_to_string(cx, seen_type),
4388-
::util::ppaux::ty_to_string(cx, ty));
4378+
debug!("ContainsRecursive: {} contains {}",
4379+
seen_type.repr(cx),
4380+
ty.repr(cx));
43894381
return ContainsRecursive;
43904382
}
43914383
}
@@ -4405,16 +4397,14 @@ pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>)
44054397
}
44064398
}
44074399

4408-
debug!("is_type_representable: {:?}",
4409-
::util::ppaux::ty_to_string(cx, ty));
4400+
debug!("is_type_representable: {}", ty.repr(cx));
44104401

44114402
// To avoid a stack overflow when checking an enum variant or struct that
44124403
// contains a different, structurally recursive type, maintain a stack
44134404
// of seen types and check recursion for each of them (issues #3008, #3779).
44144405
let mut seen: Vec<Ty> = Vec::new();
44154406
let r = is_type_structurally_recursive(cx, sp, &mut seen, ty);
4416-
debug!("is_type_representable: {:?} is {:?}",
4417-
::util::ppaux::ty_to_string(cx, ty), r);
4407+
debug!("is_type_representable: {} is {:?}", ty.repr(cx), r);
44184408
r
44194409
}
44204410

@@ -4857,7 +4847,7 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
48574847
span,
48584848
&format!("the {}th autoderef failed: {}",
48594849
i,
4860-
ty_to_string(cx, adjusted_ty))
4850+
adjusted_ty.user_string(cx))
48614851
);
48624852
}
48634853
}
@@ -5102,10 +5092,8 @@ pub fn impl_or_trait_item_idx(id: ast::Name, trait_items: &[ImplOrTraitItem])
51025092
pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
51035093
match ty.sty {
51045094
TyBool | TyChar | TyInt(_) |
5105-
TyUint(_) | TyFloat(_) | TyStr => {
5106-
::util::ppaux::ty_to_string(cx, ty)
5107-
}
5108-
TyTuple(ref tys) if tys.is_empty() => ::util::ppaux::ty_to_string(cx, ty),
5095+
TyUint(_) | TyFloat(_) | TyStr => ty.user_string(cx),
5096+
TyTuple(ref tys) if tys.is_empty() => ty.user_string(cx),
51095097

51105098
TyEnum(id, _) => format!("enum `{}`", item_path_str(cx, id)),
51115099
TyBox(_) => "box".to_string(),

trunk/src/librustc/util/ppaux.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn mutability_to_string(m: ast::Mutability) -> String {
186186
pub fn mt_to_string<'tcx>(cx: &ctxt<'tcx>, m: &mt<'tcx>) -> String {
187187
format!("{}{}",
188188
mutability_to_string(m.mutbl),
189-
ty_to_string(cx, m.ty))
189+
m.ty.user_string(cx))
190190
}
191191

192192
pub fn vec_map_to_string<T, F>(ts: &[T], f: F) -> String where
@@ -196,7 +196,7 @@ pub fn vec_map_to_string<T, F>(ts: &[T], f: F) -> String where
196196
format!("[{}]", tstrs.connect(", "))
197197
}
198198

199-
pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
199+
fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
200200
fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
201201
opt_def_id: Option<ast::DefId>,
202202
unsafety: ast::Unsafety,
@@ -266,7 +266,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
266266
s.push(bra);
267267
let strs = sig.0.inputs
268268
.iter()
269-
.map(|a| ty_to_string(cx, *a))
269+
.map(|a| a.user_string(cx))
270270
.collect::<Vec<_>>();
271271
s.push_str(&strs.connect(", "));
272272
if sig.0.variadic {
@@ -278,7 +278,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
278278
ty::FnConverging(t) => {
279279
if !ty::type_is_nil(t) {
280280
s.push_str(" -> ");
281-
s.push_str(&ty_to_string(cx, t));
281+
s.push_str(& t.user_string(cx));
282282
}
283283
}
284284
ty::FnDiverging => {
@@ -307,12 +307,12 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
307307
TyInt(t) => ast_util::int_ty_to_string(t, None).to_string(),
308308
TyUint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
309309
TyFloat(t) => ast_util::float_ty_to_string(t).to_string(),
310-
TyBox(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
310+
TyBox(typ) => format!("Box<{}>", typ.user_string(cx)),
311311
TyRawPtr(ref tm) => {
312312
format!("*{} {}", match tm.mutbl {
313313
ast::MutMutable => "mut",
314314
ast::MutImmutable => "const",
315-
}, ty_to_string(cx, tm.ty))
315+
}, tm.ty.user_string(cx))
316316
}
317317
TyRef(r, ref tm) => {
318318
let mut buf = "&".to_owned();
@@ -326,7 +326,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
326326
TyTuple(ref elems) => {
327327
let strs = elems
328328
.iter()
329-
.map(|elem| ty_to_string(cx, *elem))
329+
.map(|elem| elem.user_string(cx))
330330
.collect::<Vec<_>>();
331331
match &strs[..] {
332332
[ref string] => format!("({},)", string),
@@ -375,10 +375,10 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
375375
})
376376
}
377377
TyArray(t, sz) => {
378-
format!("[{}; {}]", ty_to_string(cx, t), sz)
378+
format!("[{}; {}]", t.user_string(cx), sz)
379379
}
380380
TySlice(t) => {
381-
format!("[{}]", ty_to_string(cx, t))
381+
format!("[{}]", t.user_string(cx))
382382
}
383383
}
384384
}
@@ -475,7 +475,7 @@ fn parameterized<'tcx, GG>(cx: &ctxt<'tcx>,
475475
};
476476

477477
for t in &tps[..tps.len() - num_defaults] {
478-
strs.push(ty_to_string(cx, *t))
478+
strs.push(t.user_string(cx))
479479
}
480480

481481
for projection in projections {
@@ -581,6 +581,12 @@ impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Vec<T> {
581581
}
582582
}
583583

584+
impl<'a, 'tcx, T: ?Sized +UserString<'tcx>> UserString<'tcx> for &'a T {
585+
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
586+
UserString::user_string(*self, tcx)
587+
}
588+
}
589+
584590
impl<'tcx, T:UserString<'tcx>> UserString<'tcx> for Vec<T> {
585591
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
586592
let strs: Vec<String> =
@@ -672,7 +678,7 @@ impl<'tcx> Repr<'tcx> for ty::RegionParameterDef {
672678

673679
impl<'tcx> Repr<'tcx> for ty::TyS<'tcx> {
674680
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
675-
ty_to_string(tcx, self)
681+
self.user_string(tcx)
676682
}
677683
}
678684

@@ -1290,9 +1296,9 @@ impl<'tcx> UserString<'tcx> for ty::TraitRef<'tcx> {
12901296
}
12911297
}
12921298

1293-
impl<'tcx> UserString<'tcx> for Ty<'tcx> {
1299+
impl<'tcx> UserString<'tcx> for ty::TyS<'tcx> {
12941300
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
1295-
ty_to_string(tcx, *self)
1301+
ty_to_string(tcx, self)
12961302
}
12971303
}
12981304

0 commit comments

Comments
 (0)