Skip to content

Commit 761fc16

Browse files
AatchJames Miller
authored and
James Miller
committed
Fix-up PP Code to reflect new lifetime param syntax
1 parent 048ed14 commit 761fc16

File tree

10 files changed

+60
-53
lines changed

10 files changed

+60
-53
lines changed

src/librustc/middle/mem_categorization.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use core::prelude::*;
5050

5151
use middle::ty;
5252
use middle::typeck;
53-
use util::ppaux::{ty_to_str, region_to_str, Repr};
53+
use util::ppaux::{ty_to_str, region_ptr_to_str, Repr};
5454
use util::common::indenter;
5555

5656
use core::uint;
@@ -1026,7 +1026,7 @@ impl mem_categorization_ctxt {
10261026
}
10271027

10281028
pub fn region_to_str(&self, r: ty::Region) -> ~str {
1029-
region_to_str(self.tcx, r)
1029+
region_ptr_to_str(self.tcx, r)
10301030
}
10311031
}
10321032

src/librustc/middle/trans/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ fn set_debug_location(cx: @mut CrateContext, scope: DIScope, line: uint, col: ui
693693
}
694694

695695
/// Set current debug location at the beginning of the span
696-
pub fn update_source_pos(bcx: @mut Block, span: span) {
696+
pub fn update_source_pos(bcx: block, span: span) {
697697
if !bcx.sess().opts.debuginfo || (*span.lo == 0 && *span.hi == 0) {
698698
return;
699699
}

src/librustc/middle/ty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use middle::ty;
2121
use middle::subst::Subst;
2222
use middle::typeck;
2323
use middle;
24-
use util::ppaux::{note_and_explain_region, bound_region_to_str};
24+
use util::ppaux::{note_and_explain_region, bound_region_to_str, bound_region_ptr_to_str};
2525
use util::ppaux::{trait_store_to_str, ty_to_str, vstore_to_str};
2626
use util::ppaux::{Repr, UserString};
2727
use util::common::{indenter};
@@ -3531,12 +3531,12 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
35313531
terr_regions_insufficiently_polymorphic(br, _) => {
35323532
fmt!("expected bound lifetime parameter %s, \
35333533
but found concrete lifetime",
3534-
bound_region_to_str(cx, br))
3534+
bound_region_ptr_to_str(cx, br))
35353535
}
35363536
terr_regions_overly_polymorphic(br, _) => {
35373537
fmt!("expected concrete lifetime, \
35383538
but found bound lifetime parameter %s",
3539-
bound_region_to_str(cx, br))
3539+
bound_region_ptr_to_str(cx, br))
35403540
}
35413541
terr_vstores_differ(k, ref values) => {
35423542
fmt!("%s storage differs: expected %s but found %s",

src/librustc/middle/typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ use middle::typeck::{isr_alist, lookup_def_ccx};
107107
use middle::typeck::no_params;
108108
use middle::typeck::{require_same_types, method_map, vtable_map};
109109
use util::common::{block_query, indenter, loop_query};
110-
use util::ppaux::{bound_region_to_str};
110+
use util::ppaux::{bound_region_to_str,bound_region_ptr_to_str};
111111
use util::ppaux;
112112

113113

@@ -680,7 +680,7 @@ impl FnCtxt {
680680
} else {
681681
result::Err(RegionError {
682682
msg: fmt!("named region `%s` not in scope here",
683-
bound_region_to_str(self.tcx(), br)),
683+
bound_region_ptr_to_str(self.tcx(), br)),
684684
replacement: self.infcx().next_region_var_nb(span)
685685
})
686686
}

src/librustc/middle/typeck/check/regionck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,13 @@ fn constrain_regions_in_type(
690690
let tcx = rcx.fcx.ccx.tcx;
691691

692692
debug!("constrain_regions_in_type(minimum_lifetime=%s, ty=%s)",
693-
region_to_str(tcx, minimum_lifetime),
693+
region_to_str(tcx, "", false, minimum_lifetime),
694694
ty_to_str(tcx, ty));
695695

696696
do relate_nested_regions(tcx, Some(minimum_lifetime), ty) |r_sub, r_sup| {
697697
debug!("relate(r_sub=%s, r_sup=%s)",
698-
region_to_str(tcx, r_sub),
699-
region_to_str(tcx, r_sup));
698+
region_to_str(tcx, "", false, r_sub),
699+
region_to_str(tcx, "", false, r_sup));
700700

701701
if r_sup.is_bound() || r_sub.is_bound() {
702702
// a bound region is one which appears inside an fn type.

src/librustc/middle/typeck/check/regionmanip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn replace_bound_regions_in_fn_sig(
149149
tcx.sess.bug(
150150
fmt!("Bound region not found in \
151151
in_scope_regions list: %s",
152-
region_to_str(tcx, r)));
152+
region_to_str(tcx, "", false, r)));
153153
}
154154
}
155155
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl InferCtxt {
821821
// debug message.
822822
let rvar = self.next_region_var_nb(span);
823823
debug!("Bound region %s maps to %?",
824-
bound_region_to_str(self.tcx, br),
824+
bound_region_to_str(self.tcx, "", false, br),
825825
rvar);
826826
rvar
827827
});

src/librustc/middle/typeck/infer/sub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Combine for Sub {
179179
None, b) |br| {
180180
let skol = self.infcx.region_vars.new_skolemized(br);
181181
debug!("Bound region %s skolemized to %?",
182-
bound_region_to_str(self.infcx.tcx, br),
182+
bound_region_to_str(self.infcx.tcx, "", false, br),
183183
skol);
184184
skol
185185
}

src/librustc/util/ppaux.rs

+44-37
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
112112
idx + 1),
113113
br_fresh(_) => fmt!("an anonymous lifetime defined on"),
114114
_ => fmt!("the lifetime %s as defined on",
115-
bound_region_to_str(cx, fr.bound_region))
115+
bound_region_ptr_to_str(cx, fr.bound_region))
116116
};
117117

118118
match cx.items.find(&fr.scope_id) {
@@ -147,22 +147,23 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
147147
}
148148
}
149149

150-
pub fn bound_region_to_str(cx: ctxt, br: bound_region) -> ~str {
151-
bound_region_to_str_space(cx, "&", br)
150+
pub fn bound_region_ptr_to_str(cx: ctxt, br: bound_region) -> ~str {
151+
bound_region_to_str(cx, "&", true, br)
152152
}
153153

154-
pub fn bound_region_to_str_space(cx: ctxt,
155-
prefix: &str,
156-
br: bound_region)
157-
-> ~str {
158-
if cx.sess.verbose() { return fmt!("%s%? ", prefix, br); }
154+
pub fn bound_region_to_str(cx: ctxt,
155+
prefix: &str, space: bool,
156+
br: bound_region) -> ~str {
157+
let space_str = if space { " " } else { "" };
158+
159+
if cx.sess.verbose() { return fmt!("%s%?%s", prefix, br, space_str); }
159160

160161
match br {
161-
br_named(id) => fmt!("%s'%s ", prefix, cx.sess.str_of(id)),
162-
br_self => fmt!("%s'self ", prefix),
162+
br_named(id) => fmt!("%s'%s%s", prefix, cx.sess.str_of(id), space_str),
163+
br_self => fmt!("%s'self%s", prefix, space_str),
163164
br_anon(_) => prefix.to_str(),
164165
br_fresh(_) => prefix.to_str(),
165-
br_cap_avoid(_, br) => bound_region_to_str_space(cx, prefix, *br)
166+
br_cap_avoid(_, br) => bound_region_to_str(cx, prefix, space, *br)
166167
}
167168
}
168169

@@ -208,13 +209,15 @@ pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
208209
// In general, if you are giving a region error message,
209210
// you should use `explain_region()` or, better yet,
210211
// `note_and_explain_region()`
211-
pub fn region_to_str(cx: ctxt, region: Region) -> ~str {
212-
region_to_str_space(cx, "&", region)
212+
pub fn region_ptr_to_str(cx: ctxt, region: Region) -> ~str {
213+
region_to_str(cx, "&", true, region)
213214
}
214215

215-
pub fn region_to_str_space(cx: ctxt, prefix: &str, region: Region) -> ~str {
216+
pub fn region_to_str(cx: ctxt, prefix: &str, space: bool, region: Region) -> ~str {
217+
let space_str = if space { " " } else { "" };
218+
216219
if cx.sess.verbose() {
217-
return fmt!("%s%? ", prefix, region);
220+
return fmt!("%s%?%s", prefix, region, space_str);
218221
}
219222

220223
// These printouts are concise. They do not contain all the information
@@ -223,14 +226,14 @@ pub fn region_to_str_space(cx: ctxt, prefix: &str, region: Region) -> ~str {
223226
// `explain_region()` or `note_and_explain_region()`.
224227
match region {
225228
re_scope(_) => prefix.to_str(),
226-
re_bound(br) => bound_region_to_str_space(cx, prefix, br),
227-
re_free(ref fr) => bound_region_to_str_space(cx, prefix, fr.bound_region),
229+
re_bound(br) => bound_region_to_str(cx, prefix, space, br),
230+
re_free(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
228231
re_infer(ReSkolemized(_, br)) => {
229-
bound_region_to_str_space(cx, prefix, br)
232+
bound_region_to_str(cx, prefix, space, br)
230233
}
231234
re_infer(ReVar(_)) => prefix.to_str(),
232-
re_static => fmt!("%s'static ", prefix),
233-
re_empty => fmt!("%s'<empty> ", prefix)
235+
re_static => fmt!("%s'static%s", prefix, space_str),
236+
re_empty => fmt!("%s'<empty>%s", prefix, space_str)
234237
}
235238
}
236239

@@ -256,15 +259,15 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
256259
ty::vstore_fixed(n) => fmt!("%u", n),
257260
ty::vstore_uniq => ~"~",
258261
ty::vstore_box => ~"@",
259-
ty::vstore_slice(r) => region_to_str_space(cx, "&", r)
262+
ty::vstore_slice(r) => region_ptr_to_str(cx, r)
260263
}
261264
}
262265
263266
pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
264267
match s {
265268
ty::UniqTraitStore => ~"~",
266269
ty::BoxTraitStore => ~"@",
267-
ty::RegionTraitStore(r) => region_to_str_space(cx, "&", r)
270+
ty::RegionTraitStore(r) => region_ptr_to_str(cx, r)
268271
}
269272
}
270273

@@ -340,7 +343,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
340343
(ast::OwnedSigil, ty::re_static) => {}
341344

342345
(_, region) => {
343-
s.push_str(region_to_str_space(cx, "", region));
346+
s.push_str(region_to_str(cx, "", true, region));
344347
}
345348
}
346349

@@ -414,7 +417,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
414417
ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm),
415418
ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
416419
ty_rptr(r, ref tm) => {
417-
region_to_str_space(cx, "&", r) + mt_to_str(cx, tm)
420+
region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
418421
}
419422
ty_unboxed_vec(ref tm) => { fmt!("unboxed_vec<%s>", mt_to_str(cx, tm)) }
420423
ty_type => ~"type",
@@ -431,13 +434,15 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
431434
ty_infer(infer_ty) => infer_ty.to_str(),
432435
ty_err => ~"[type error]",
433436
ty_param(param_ty {idx: id, def_id: did}) => {
437+
let mut parm = (('T' as uint) + id) as char;
438+
if (parm as uint) > ('Z' as uint) {
439+
parm = (parm as uint - 26) as char;
440+
}
441+
434442
if cx.sess.verbose() {
435-
fmt!("'%s:%?",
436-
str::from_bytes([('a' as u8) + (id as u8)]),
437-
did)
443+
fmt!("%c:%?", parm, did)
438444
} else {
439-
fmt!("'%s",
440-
str::from_bytes([('a' as u8) + (id as u8)]))
445+
fmt!("%c", parm)
441446
}
442447
}
443448
ty_self(*) => ~"Self",
@@ -468,18 +473,20 @@ pub fn parameterized(cx: ctxt,
468473
self_r: Option<ty::Region>,
469474
tps: &[ty::t]) -> ~str {
470475

471-
let r_str = match self_r {
472-
None => ~"",
476+
let mut strs = ~[];
477+
match self_r {
478+
None => (),
473479
Some(r) => {
474-
region_to_str(cx, r)
480+
strs.push(region_to_str(cx, "", false, r))
475481
}
476482
};
477483

478-
if tps.len() > 0u {
479-
let strs = vec::map(tps, |t| ty_to_str(cx, *t));
480-
fmt!("%s%s<%s>", r_str, base, strs.connect(","))
484+
strs += vec::map(tps, |t| ty_to_str(cx, *t));
485+
486+
if strs.len() > 0u {
487+
fmt!("%s<%s>", base, strs.connect(","))
481488
} else {
482-
fmt!("%s%s", r_str, base)
489+
fmt!("%s", base)
483490
}
484491
}
485492

@@ -597,7 +604,7 @@ impl Repr for @ast::pat {
597604

598605
impl Repr for ty::Region {
599606
fn repr(&self, tcx: ctxt) -> ~str {
600-
region_to_str(tcx, *self)
607+
region_to_str(tcx, "", false, *self)
601608
}
602609
}
603610

src/test/compile-fail/regions-bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ struct an_enum<'self>(&'self int);
1616
struct a_class<'self> { x:&'self int }
1717

1818
fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> {
19-
return e; //~ ERROR mismatched types: expected `an_enum/&'b ` but found `an_enum/&'a `
19+
return e; //~ ERROR mismatched types: expected `an_enum<'b>` but found `an_enum<'a>`
2020
}
2121

2222
fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> {
23-
return e; //~ ERROR mismatched types: expected `a_class/&'b ` but found `a_class/&'a `
23+
return e; //~ ERROR mismatched types: expected `a_class<'b>` but found `a_class<'a>`
2424
}
2525

2626
fn a_fn4<'a,'b>() {

0 commit comments

Comments
 (0)