Skip to content

Commit

Permalink
Fix-up PP Code to reflect new lifetime param syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Aatch authored and James Miller committed Jun 22, 2013
1 parent 048ed14 commit 761fc16
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -50,7 +50,7 @@ use core::prelude::*;

use middle::ty;
use middle::typeck;
use util::ppaux::{ty_to_str, region_to_str, Repr};
use util::ppaux::{ty_to_str, region_ptr_to_str, Repr};
use util::common::indenter;

use core::uint;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ impl mem_categorization_ctxt {
}

pub fn region_to_str(&self, r: ty::Region) -> ~str {
region_to_str(self.tcx, r)
region_ptr_to_str(self.tcx, r)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/debuginfo.rs
Expand Up @@ -693,7 +693,7 @@ fn set_debug_location(cx: @mut CrateContext, scope: DIScope, line: uint, col: ui
}

/// Set current debug location at the beginning of the span
pub fn update_source_pos(bcx: @mut Block, span: span) {
pub fn update_source_pos(bcx: block, span: span) {
if !bcx.sess().opts.debuginfo || (*span.lo == 0 && *span.hi == 0) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty.rs
Expand Up @@ -21,7 +21,7 @@ use middle::ty;
use middle::subst::Subst;
use middle::typeck;
use middle;
use util::ppaux::{note_and_explain_region, bound_region_to_str};
use util::ppaux::{note_and_explain_region, bound_region_to_str, bound_region_ptr_to_str};
use util::ppaux::{trait_store_to_str, ty_to_str, vstore_to_str};
use util::ppaux::{Repr, UserString};
use util::common::{indenter};
Expand Down Expand Up @@ -3531,12 +3531,12 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
terr_regions_insufficiently_polymorphic(br, _) => {
fmt!("expected bound lifetime parameter %s, \
but found concrete lifetime",
bound_region_to_str(cx, br))
bound_region_ptr_to_str(cx, br))
}
terr_regions_overly_polymorphic(br, _) => {
fmt!("expected concrete lifetime, \
but found bound lifetime parameter %s",
bound_region_to_str(cx, br))
bound_region_ptr_to_str(cx, br))
}
terr_vstores_differ(k, ref values) => {
fmt!("%s storage differs: expected %s but found %s",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -107,7 +107,7 @@ use middle::typeck::{isr_alist, lookup_def_ccx};
use middle::typeck::no_params;
use middle::typeck::{require_same_types, method_map, vtable_map};
use util::common::{block_query, indenter, loop_query};
use util::ppaux::{bound_region_to_str};
use util::ppaux::{bound_region_to_str,bound_region_ptr_to_str};
use util::ppaux;


Expand Down Expand Up @@ -680,7 +680,7 @@ impl FnCtxt {
} else {
result::Err(RegionError {
msg: fmt!("named region `%s` not in scope here",
bound_region_to_str(self.tcx(), br)),
bound_region_ptr_to_str(self.tcx(), br)),
replacement: self.infcx().next_region_var_nb(span)
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/typeck/check/regionck.rs
Expand Up @@ -690,13 +690,13 @@ fn constrain_regions_in_type(
let tcx = rcx.fcx.ccx.tcx;

debug!("constrain_regions_in_type(minimum_lifetime=%s, ty=%s)",
region_to_str(tcx, minimum_lifetime),
region_to_str(tcx, "", false, minimum_lifetime),
ty_to_str(tcx, ty));

do relate_nested_regions(tcx, Some(minimum_lifetime), ty) |r_sub, r_sup| {
debug!("relate(r_sub=%s, r_sup=%s)",
region_to_str(tcx, r_sub),
region_to_str(tcx, r_sup));
region_to_str(tcx, "", false, r_sub),
region_to_str(tcx, "", false, r_sup));

if r_sup.is_bound() || r_sub.is_bound() {
// a bound region is one which appears inside an fn type.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/regionmanip.rs
Expand Up @@ -149,7 +149,7 @@ pub fn replace_bound_regions_in_fn_sig(
tcx.sess.bug(
fmt!("Bound region not found in \
in_scope_regions list: %s",
region_to_str(tcx, r)));
region_to_str(tcx, "", false, r)));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/infer/mod.rs
Expand Up @@ -821,7 +821,7 @@ impl InferCtxt {
// debug message.
let rvar = self.next_region_var_nb(span);
debug!("Bound region %s maps to %?",
bound_region_to_str(self.tcx, br),
bound_region_to_str(self.tcx, "", false, br),
rvar);
rvar
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/infer/sub.rs
Expand Up @@ -179,7 +179,7 @@ impl Combine for Sub {
None, b) |br| {
let skol = self.infcx.region_vars.new_skolemized(br);
debug!("Bound region %s skolemized to %?",
bound_region_to_str(self.infcx.tcx, br),
bound_region_to_str(self.infcx.tcx, "", false, br),
skol);
skol
}
Expand Down
81 changes: 44 additions & 37 deletions src/librustc/util/ppaux.rs
Expand Up @@ -112,7 +112,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
idx + 1),
br_fresh(_) => fmt!("an anonymous lifetime defined on"),
_ => fmt!("the lifetime %s as defined on",
bound_region_to_str(cx, fr.bound_region))
bound_region_ptr_to_str(cx, fr.bound_region))
};

match cx.items.find(&fr.scope_id) {
Expand Down Expand Up @@ -147,22 +147,23 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
}
}

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

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

if cx.sess.verbose() { return fmt!("%s%?%s", prefix, br, space_str); }

match br {
br_named(id) => fmt!("%s'%s ", prefix, cx.sess.str_of(id)),
br_self => fmt!("%s'self ", prefix),
br_named(id) => fmt!("%s'%s%s", prefix, cx.sess.str_of(id), space_str),
br_self => fmt!("%s'self%s", prefix, space_str),
br_anon(_) => prefix.to_str(),
br_fresh(_) => prefix.to_str(),
br_cap_avoid(_, br) => bound_region_to_str_space(cx, prefix, *br)
br_cap_avoid(_, br) => bound_region_to_str(cx, prefix, space, *br)
}
}

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

pub fn region_to_str_space(cx: ctxt, prefix: &str, region: Region) -> ~str {
pub fn region_to_str(cx: ctxt, prefix: &str, space: bool, region: Region) -> ~str {
let space_str = if space { " " } else { "" };

if cx.sess.verbose() {
return fmt!("%s%? ", prefix, region);
return fmt!("%s%?%s", prefix, region, space_str);
}

// These printouts are concise. They do not contain all the information
Expand All @@ -223,14 +226,14 @@ pub fn region_to_str_space(cx: ctxt, prefix: &str, region: Region) -> ~str {
// `explain_region()` or `note_and_explain_region()`.
match region {
re_scope(_) => prefix.to_str(),
re_bound(br) => bound_region_to_str_space(cx, prefix, br),
re_free(ref fr) => bound_region_to_str_space(cx, prefix, fr.bound_region),
re_bound(br) => bound_region_to_str(cx, prefix, space, br),
re_free(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
re_infer(ReSkolemized(_, br)) => {
bound_region_to_str_space(cx, prefix, br)
bound_region_to_str(cx, prefix, space, br)
}
re_infer(ReVar(_)) => prefix.to_str(),
re_static => fmt!("%s'static ", prefix),
re_empty => fmt!("%s'<empty> ", prefix)
re_static => fmt!("%s'static%s", prefix, space_str),
re_empty => fmt!("%s'<empty>%s", prefix, space_str)
}
}

Expand All @@ -256,15 +259,15 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
ty::vstore_fixed(n) => fmt!("%u", n),
ty::vstore_uniq => ~"~",
ty::vstore_box => ~"@",
ty::vstore_slice(r) => region_to_str_space(cx, "&", r)
ty::vstore_slice(r) => region_ptr_to_str(cx, r)
}
}
pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
match s {
ty::UniqTraitStore => ~"~",
ty::BoxTraitStore => ~"@",
ty::RegionTraitStore(r) => region_to_str_space(cx, "&", r)
ty::RegionTraitStore(r) => region_ptr_to_str(cx, r)
}
}

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

(_, region) => {
s.push_str(region_to_str_space(cx, "", region));
s.push_str(region_to_str(cx, "", true, region));
}
}

Expand Down Expand Up @@ -414,7 +417,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm),
ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
ty_rptr(r, ref tm) => {
region_to_str_space(cx, "&", r) + mt_to_str(cx, tm)
region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
}
ty_unboxed_vec(ref tm) => { fmt!("unboxed_vec<%s>", mt_to_str(cx, tm)) }
ty_type => ~"type",
Expand All @@ -431,13 +434,15 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ty_infer(infer_ty) => infer_ty.to_str(),
ty_err => ~"[type error]",
ty_param(param_ty {idx: id, def_id: did}) => {
let mut parm = (('T' as uint) + id) as char;
if (parm as uint) > ('Z' as uint) {
parm = (parm as uint - 26) as char;
}

if cx.sess.verbose() {
fmt!("'%s:%?",
str::from_bytes([('a' as u8) + (id as u8)]),
did)
fmt!("%c:%?", parm, did)
} else {
fmt!("'%s",
str::from_bytes([('a' as u8) + (id as u8)]))
fmt!("%c", parm)
}
}
ty_self(*) => ~"Self",
Expand Down Expand Up @@ -468,18 +473,20 @@ pub fn parameterized(cx: ctxt,
self_r: Option<ty::Region>,
tps: &[ty::t]) -> ~str {

let r_str = match self_r {
None => ~"",
let mut strs = ~[];
match self_r {
None => (),
Some(r) => {
region_to_str(cx, r)
strs.push(region_to_str(cx, "", false, r))
}
};

if tps.len() > 0u {
let strs = vec::map(tps, |t| ty_to_str(cx, *t));
fmt!("%s%s<%s>", r_str, base, strs.connect(","))
strs += vec::map(tps, |t| ty_to_str(cx, *t));

if strs.len() > 0u {
fmt!("%s<%s>", base, strs.connect(","))
} else {
fmt!("%s%s", r_str, base)
fmt!("%s", base)
}
}

Expand Down Expand Up @@ -597,7 +604,7 @@ impl Repr for @ast::pat {

impl Repr for ty::Region {
fn repr(&self, tcx: ctxt) -> ~str {
region_to_str(tcx, *self)
region_to_str(tcx, "", false, *self)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-bounds.rs
Expand Up @@ -16,11 +16,11 @@ struct an_enum<'self>(&'self int);
struct a_class<'self> { x:&'self int }

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

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

fn a_fn4<'a,'b>() {
Expand Down

0 comments on commit 761fc16

Please sign in to comment.