Skip to content

Commit 9ea24e3

Browse files
committed
---
yaml --- r: 213969 b: refs/heads/master c: 4e0cb86 h: refs/heads/master i: 213967: 3e45faf v: v3
1 parent 2b484e4 commit 9ea24e3

File tree

7 files changed

+102
-143
lines changed

7 files changed

+102
-143
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: bc383f62941ae079188a9725eb49f3b8a42e35ae
2+
refs/heads/master: 4e0cb86a5c173096b08819af37f57970ac332561
33
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ use syntax::codemap;
8888
use syntax::parse::token;
8989
use syntax::print::pprust;
9090
use syntax::ptr::P;
91-
use util::ppaux::bound_region_to_string;
9291
use util::ppaux::note_and_explain_region;
9392

9493
// Note: only import UserString, not Repr, since user-facing error
@@ -1441,24 +1440,29 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
14411440

14421441
fn report_inference_failure(&self,
14431442
var_origin: RegionVariableOrigin) {
1443+
let br_string = |br: ty::BoundRegion| {
1444+
let mut s = br.user_string(self.tcx);
1445+
if !s.is_empty() {
1446+
s.push_str(" ");
1447+
}
1448+
s
1449+
};
14441450
let var_description = match var_origin {
14451451
infer::MiscVariable(_) => "".to_string(),
14461452
infer::PatternRegion(_) => " for pattern".to_string(),
14471453
infer::AddrOfRegion(_) => " for borrow expression".to_string(),
14481454
infer::Autoref(_) => " for autoref".to_string(),
14491455
infer::Coercion(_) => " for automatic coercion".to_string(),
14501456
infer::LateBoundRegion(_, br, infer::FnCall) => {
1451-
format!(" for {}in function call",
1452-
bound_region_to_string(self.tcx, "lifetime parameter ", true, br))
1457+
format!(" for lifetime parameter {}in function call",
1458+
br_string(br))
14531459
}
14541460
infer::LateBoundRegion(_, br, infer::HigherRankedType) => {
1455-
format!(" for {}in generic type",
1456-
bound_region_to_string(self.tcx, "lifetime parameter ", true, br))
1461+
format!(" for lifetime parameter {}in generic type", br_string(br))
14571462
}
14581463
infer::LateBoundRegion(_, br, infer::AssocTypeProjection(type_name)) => {
1459-
format!(" for {}in trait containing associated type `{}`",
1460-
bound_region_to_string(self.tcx, "lifetime parameter ", true, br),
1461-
token::get_name(type_name))
1464+
format!(" for lifetime parameter {}in trait containing associated type `{}`",
1465+
br_string(br), token::get_name(type_name))
14621466
}
14631467
infer::EarlyBoundRegion(_, name) => {
14641468
format!(" for lifetime parameter `{}`",

trunk/src/librustc/middle/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use middle::traits;
6161
use middle::ty;
6262
use middle::ty_fold::{self, TypeFoldable, TypeFolder};
6363
use middle::ty_walk::{self, TypeWalker};
64-
use util::ppaux::{note_and_explain_region, bound_region_ptr_to_string};
64+
use util::ppaux::note_and_explain_region;
6565
use util::ppaux::ty_to_string;
6666
use util::ppaux::{Repr, UserString};
6767
use util::common::{memoized, ErrorReported};
@@ -5205,12 +5205,12 @@ pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
52055205
terr_regions_insufficiently_polymorphic(br, _) => {
52065206
format!("expected bound lifetime parameter {}, \
52075207
found concrete lifetime",
5208-
bound_region_ptr_to_string(cx, br))
5208+
br.user_string(cx))
52095209
}
52105210
terr_regions_overly_polymorphic(br, _) => {
52115211
format!("expected concrete lifetime, \
52125212
found bound lifetime parameter {}",
5213-
bound_region_ptr_to_string(cx, br))
5213+
br.user_string(cx))
52145214
}
52155215
terr_sorts(values) => {
52165216
// A naive approach to making sure that we're not reporting silly errors such as:

trunk/src/librustc/util/ppaux.rs

Lines changed: 67 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,13 @@ pub trait UserString<'tcx> : Repr<'tcx> {
5252
pub fn note_and_explain_region(cx: &ctxt,
5353
prefix: &str,
5454
region: ty::Region,
55-
suffix: &str) -> Option<Span> {
56-
match explain_region_and_span(cx, region) {
57-
(ref str, Some(span)) => {
58-
cx.sess.span_note(
59-
span,
60-
&format!("{}{}{}", prefix, *str, suffix));
61-
Some(span)
62-
}
63-
(ref str, None) => {
64-
cx.sess.note(
65-
&format!("{}{}{}", prefix, *str, suffix));
66-
None
67-
}
55+
suffix: &str) {
56+
let (description, span) = explain_region_and_span(cx, region);
57+
let message = format!("{}{}{}", prefix, description, suffix);
58+
if let Some(span) = span {
59+
cx.sess.span_note(span, &message);
60+
} else {
61+
cx.sess.note(&message);
6862
}
6963
}
7064

@@ -81,8 +75,8 @@ fn item_scope_tag(item: &ast::Item) -> &'static str {
8175
}
8276
}
8377

84-
pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
85-
-> (String, Option<Span>) {
78+
fn explain_region_and_span(cx: &ctxt, region: ty::Region)
79+
-> (String, Option<Span>) {
8680
return match region {
8781
ReScope(scope) => {
8882
let new_string;
@@ -138,7 +132,7 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
138132
BrFresh(_) => "an anonymous lifetime defined on".to_string(),
139133
_ => {
140134
format!("the lifetime {} as defined on",
141-
bound_region_ptr_to_string(cx, fr.bound_region))
135+
fr.bound_region.user_string(cx))
142136
}
143137
};
144138

@@ -182,61 +176,6 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
182176
}
183177
}
184178

185-
pub fn bound_region_ptr_to_string(cx: &ctxt, br: BoundRegion) -> String {
186-
bound_region_to_string(cx, "", false, br)
187-
}
188-
189-
pub fn bound_region_to_string(cx: &ctxt,
190-
prefix: &str, space: bool,
191-
br: BoundRegion) -> String {
192-
let space_str = if space { " " } else { "" };
193-
194-
if cx.sess.verbose() {
195-
return format!("{}{}{}", prefix, br.repr(cx), space_str)
196-
}
197-
198-
match br {
199-
BrNamed(_, name) => {
200-
format!("{}{}{}", prefix, token::get_name(name), space_str)
201-
}
202-
BrAnon(_) | BrFresh(_) | BrEnv => prefix.to_string()
203-
}
204-
}
205-
206-
// In general, if you are giving a region error message,
207-
// you should use `explain_region()` or, better yet,
208-
// `note_and_explain_region()`
209-
pub fn region_ptr_to_string(cx: &ctxt, region: Region) -> String {
210-
region_to_string(cx, "&", true, region)
211-
}
212-
213-
pub fn region_to_string(cx: &ctxt, prefix: &str, space: bool, region: Region) -> String {
214-
let space_str = if space { " " } else { "" };
215-
216-
if cx.sess.verbose() {
217-
return format!("{}{}{}", prefix, region.repr(cx), space_str)
218-
}
219-
220-
// These printouts are concise. They do not contain all the information
221-
// the user might want to diagnose an error, but there is basically no way
222-
// to fit that into a short string. Hence the recommendation to use
223-
// `explain_region()` or `note_and_explain_region()`.
224-
match region {
225-
ty::ReScope(_) => prefix.to_string(),
226-
ty::ReEarlyBound(ref data) => {
227-
token::get_name(data.name).to_string()
228-
}
229-
ty::ReLateBound(_, br) => bound_region_to_string(cx, prefix, space, br),
230-
ty::ReFree(ref fr) => bound_region_to_string(cx, prefix, space, fr.bound_region),
231-
ty::ReInfer(ReSkolemized(_, br)) => {
232-
bound_region_to_string(cx, prefix, space, br)
233-
}
234-
ty::ReInfer(ReVar(_)) => prefix.to_string(),
235-
ty::ReStatic => format!("{}'static{}", prefix, space_str),
236-
ty::ReEmpty => format!("{}'<empty>{}", prefix, space_str),
237-
}
238-
}
239-
240179
pub fn mutability_to_string(m: ast::Mutability) -> String {
241180
match m {
242181
ast::MutMutable => "mut ".to_string(),
@@ -376,7 +315,11 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
376315
}, ty_to_string(cx, tm.ty))
377316
}
378317
TyRef(r, ref tm) => {
379-
let mut buf = region_ptr_to_string(cx, *r);
318+
let mut buf = "&".to_owned();
319+
buf.push_str(&r.user_string(cx));
320+
if !buf.is_empty() {
321+
buf.push_str(" ");
322+
}
380323
buf.push_str(&mt_to_string(cx, tm));
381324
buf
382325
}
@@ -440,26 +383,13 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
440383
}
441384
}
442385

443-
pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
444-
-> &'static str {
445-
match *category {
446-
ty::StaticExplicitSelfCategory => "static",
447-
ty::ByValueExplicitSelfCategory => "self",
448-
ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
449-
"&mut self"
450-
}
451-
ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
452-
ty::ByBoxExplicitSelfCategory => "Box<self>",
453-
}
454-
}
455-
456-
pub fn parameterized<'tcx,GG>(cx: &ctxt<'tcx>,
457-
base: &str,
458-
substs: &subst::Substs<'tcx>,
459-
did: ast::DefId,
460-
projections: &[ty::ProjectionPredicate<'tcx>],
461-
get_generics: GG)
462-
-> String
386+
fn parameterized<'tcx, GG>(cx: &ctxt<'tcx>,
387+
base: &str,
388+
substs: &subst::Substs<'tcx>,
389+
did: ast::DefId,
390+
projections: &[ty::ProjectionPredicate<'tcx>],
391+
get_generics: GG)
392+
-> String
463393
where GG : FnOnce() -> ty::Generics<'tcx>
464394
{
465395
if cx.sess.verbose() {
@@ -495,7 +425,7 @@ pub fn parameterized<'tcx,GG>(cx: &ctxt<'tcx>,
495425
subst::ErasedRegions => { }
496426
subst::NonerasedRegions(ref regions) => {
497427
for &r in regions {
498-
let s = region_to_string(cx, "", false, r);
428+
let s = r.user_string(cx);
499429
if s.is_empty() {
500430
// This happens when the value of the region
501431
// parameter is not easily serialized. This may be
@@ -579,14 +509,6 @@ pub fn parameterized<'tcx,GG>(cx: &ctxt<'tcx>,
579509
}
580510
}
581511

582-
pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String {
583-
let mut s = typ.repr(cx).to_string();
584-
if s.len() >= 32 {
585-
s = (&s[0..32]).to_string();
586-
}
587-
return s;
588-
}
589-
590512
impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Option<T> {
591513
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
592514
match self {
@@ -915,6 +837,19 @@ impl<'tcx> Repr<'tcx> for ty::BoundRegion {
915837
}
916838
}
917839

840+
impl<'tcx> UserString<'tcx> for ty::BoundRegion {
841+
fn user_string(&self, tcx: &ctxt) -> String {
842+
if tcx.sess.verbose() {
843+
return self.repr(tcx);
844+
}
845+
846+
match *self {
847+
BrNamed(_, name) => token::get_name(name).to_string(),
848+
BrAnon(_) | BrFresh(_) | BrEnv => String::new()
849+
}
850+
}
851+
}
852+
918853
impl<'tcx> Repr<'tcx> for ty::Region {
919854
fn repr(&self, tcx: &ctxt) -> String {
920855
match *self {
@@ -959,7 +894,28 @@ impl<'tcx> Repr<'tcx> for ty::Region {
959894

960895
impl<'tcx> UserString<'tcx> for ty::Region {
961896
fn user_string(&self, tcx: &ctxt) -> String {
962-
region_to_string(tcx, "", false, *self)
897+
if tcx.sess.verbose() {
898+
return self.repr(tcx);
899+
}
900+
901+
// These printouts are concise. They do not contain all the information
902+
// the user might want to diagnose an error, but there is basically no way
903+
// to fit that into a short string. Hence the recommendation to use
904+
// `explain_region()` or `note_and_explain_region()`.
905+
match *self {
906+
ty::ReEarlyBound(ref data) => {
907+
token::get_name(data.name).to_string()
908+
}
909+
ty::ReLateBound(_, br) |
910+
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
911+
ty::ReInfer(ReSkolemized(_, br)) => {
912+
br.user_string(tcx)
913+
}
914+
ty::ReScope(_) |
915+
ty::ReInfer(ReVar(_)) => String::new(),
916+
ty::ReStatic => "'static".to_owned(),
917+
ty::ReEmpty => "'<empty>".to_owned(),
918+
}
963919
}
964920
}
965921

@@ -1446,7 +1402,15 @@ impl<'tcx> Repr<'tcx> for ast::FloatTy {
14461402

14471403
impl<'tcx> Repr<'tcx> for ty::ExplicitSelfCategory {
14481404
fn repr(&self, _: &ctxt) -> String {
1449-
explicit_self_category_to_str(self).to_string()
1405+
match *self {
1406+
ty::StaticExplicitSelfCategory => "static",
1407+
ty::ByValueExplicitSelfCategory => "self",
1408+
ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
1409+
"&mut self"
1410+
}
1411+
ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
1412+
ty::ByBoxExplicitSelfCategory => "Box<self>",
1413+
}.to_owned()
14501414
}
14511415
}
14521416

trunk/src/librustc_borrowck/borrowck/mod.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,20 +1001,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10011001
"reference must be valid for ",
10021002
sub_scope,
10031003
"...");
1004-
let suggestion = if is_statement_scope(self.tcx, super_scope) {
1005-
Some("consider using a `let` binding to increase its lifetime")
1006-
} else {
1007-
None
1008-
};
1009-
let span = note_and_explain_region(
1004+
note_and_explain_region(
10101005
self.tcx,
10111006
"...but borrowed value is only valid for ",
10121007
super_scope,
10131008
"");
1014-
match (span, suggestion) {
1015-
(_, None) => {},
1016-
(Some(span), Some(msg)) => self.tcx.sess.span_help(span, msg),
1017-
(None, Some(msg)) => self.tcx.sess.help(msg),
1009+
if let Some(span) = statement_scope_span(self.tcx, super_scope) {
1010+
self.tcx.sess.span_help(span,
1011+
"consider using a `let` binding to increase its lifetime");
10181012
}
10191013
}
10201014

@@ -1127,16 +1121,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
11271121
}
11281122
}
11291123

1130-
fn is_statement_scope(tcx: &ty::ctxt, region: ty::Region) -> bool {
1131-
match region {
1132-
ty::ReScope(scope) => {
1133-
match tcx.map.find(scope.node_id()) {
1134-
Some(ast_map::NodeStmt(_)) => true,
1135-
_ => false
1136-
}
1137-
}
1138-
_ => false
1139-
}
1124+
fn statement_scope_span(tcx: &ty::ctxt, region: ty::Region) -> Option<Span> {
1125+
match region {
1126+
ty::ReScope(scope) => {
1127+
match tcx.map.find(scope.node_id()) {
1128+
Some(ast_map::NodeStmt(stmt)) => Some(stmt.span),
1129+
_ => None
1130+
}
1131+
}
1132+
_ => None
1133+
}
11401134
}
11411135

11421136
impl BitwiseOperator for LoanDataFlowOperator {

trunk/src/librustc_trans/trans/glue.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ use trans::machine::*;
3939
use trans::monomorphize;
4040
use trans::type_of::{type_of, type_of_dtor, sizing_type_of, align_of};
4141
use trans::type_::Type;
42-
use util::ppaux;
43-
use util::ppaux::{ty_to_short_str, Repr};
42+
use util::ppaux::{self, Repr};
4443

4544
use arena::TypedArena;
4645
use libc::c_uint;
@@ -247,7 +246,7 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
247246
});
248247
ccx.available_drop_glues().borrow_mut().insert(g, fn_nm);
249248

250-
let _s = StatRecorder::new(ccx, format!("drop {}", ty_to_short_str(ccx.tcx(), t)));
249+
let _s = StatRecorder::new(ccx, format!("drop {}", t.repr(ccx.tcx())));
251250

252251
let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
253252
let (arena, fcx): (TypedArena<_>, FunctionContext);

0 commit comments

Comments
 (0)