diff options
| author | James Miller <james@aatch.net> | 2013-06-18 11:49:45 +1200 |
|---|---|---|
| committer | James Miller <bladeon@gmail.com> | 2013-06-22 12:38:40 +1200 |
| commit | 761fc16c60507c1d8f1d56ccc3ae9b7fd4edbc54 (patch) | |
| tree | 98e963064a9c9d0919a5f132e0d2510acac2cace | |
| parent | 048ed1486f16191fbe72e32cc99f6f30a28a80e4 (diff) | |
Fix-up PP Code to reflect new lifetime param syntax
| -rw-r--r-- | src/librustc/middle/mem_categorization.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/trans/debuginfo.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/ty.rs | 6 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/regionck.rs | 6 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/regionmanip.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/infer/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/infer/sub.rs | 2 | ||||
| -rw-r--r-- | src/librustc/util/ppaux.rs | 81 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-bounds.rs | 4 |
10 files changed, 60 insertions, 53 deletions
diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 297b454bd83..ffb7a1daf35 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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; @@ -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) } } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 43d434b9d33..269451b1307 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -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; } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 8595adcd1c7..e67955505f6 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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}; @@ -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", diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 1ac30027116..a8ae9041482 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -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; @@ -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) }) } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 4cedb71245a..2ff8ffdd6b2 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -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. diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index 9db873a25b0..54b449eeb40 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -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))); } } } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 410e2fe23c1..2e83acfa9f4 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -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 }); diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index b0f055dc77d..c5e0e2c8f01 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -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 } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 05833a52be2..8994c81bfb9 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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) { @@ -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) } } @@ -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 @@ -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) } } @@ -256,7 +259,7 @@ 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) } } @@ -264,7 +267,7 @@ 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) } } @@ -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)); } } @@ -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", @@ -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", @@ -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) } } @@ -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) } } diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index ab2620d46fd..35ba3862438 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -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>() { |
