@@ -112,7 +112,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
112
112
idx + 1 ) ,
113
113
br_fresh( _) => fmt ! ( "an anonymous lifetime defined on" ) ,
114
114
_ => 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) )
116
116
} ;
117
117
118
118
match cx. items . find ( & fr. scope_id ) {
@@ -147,22 +147,23 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
147
147
}
148
148
}
149
149
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)
152
152
}
153
153
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) ; }
159
160
160
161
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 ) ,
163
164
br_anon( _) => prefix. to_str ( ) ,
164
165
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)
166
167
}
167
168
}
168
169
@@ -208,13 +209,15 @@ pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
208
209
// In general, if you are giving a region error message,
209
210
// you should use `explain_region()` or, better yet,
210
211
// `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)
213
214
}
214
215
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
+
216
219
if cx. sess . verbose ( ) {
217
- return fmt ! ( "%s%? " , prefix, region) ;
220
+ return fmt ! ( "%s%?%s " , prefix, region, space_str ) ;
218
221
}
219
222
220
223
// 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 {
223
226
// `explain_region()` or `note_and_explain_region()`.
224
227
match region {
225
228
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 ) ,
228
231
re_infer( ReSkolemized ( _, br) ) => {
229
- bound_region_to_str_space ( cx, prefix, br)
232
+ bound_region_to_str ( cx, prefix, space , br)
230
233
}
231
234
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 )
234
237
}
235
238
}
236
239
@@ -256,15 +259,15 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
256
259
ty : : vstore_fixed( n) => fmt ! ( "%u" , n) ,
257
260
ty : : vstore_uniq => ~"~",
258
261
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)
260
263
}
261
264
}
262
265
263
266
pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str {
264
267
match s {
265
268
ty::UniqTraitStore => ~" ~",
266
269
ty:: BoxTraitStore => ~"@",
267
- ty:: RegionTraitStore ( r) => region_to_str_space ( cx, "&" , r)
270
+ ty:: RegionTraitStore ( r) => region_ptr_to_str ( cx, r)
268
271
}
269
272
}
270
273
@@ -340,7 +343,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
340
343
( ast:: OwnedSigil , ty:: re_static) => { }
341
344
342
345
( _, region) => {
343
- s. push_str ( region_to_str_space ( cx, "" , region) ) ;
346
+ s. push_str ( region_to_str ( cx, "" , true , region) ) ;
344
347
}
345
348
}
346
349
@@ -414,7 +417,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
414
417
ty_uniq( ref tm) => ~"~" + mt_to_str ( cx, tm) ,
415
418
ty_ptr( ref tm) => ~"* " + mt_to_str(cx, tm),
416
419
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)
418
421
}
419
422
ty_unboxed_vec(ref tm) => { fmt!(" unboxed_vec<%s>", mt_to_str(cx, tm)) }
420
423
ty_type => ~" type",
@@ -431,13 +434,15 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
431
434
ty_infer( infer_ty) => infer_ty. to_str ( ) ,
432
435
ty_err => ~"[ type error] ",
433
436
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
+
434
442
if cx. sess . verbose ( ) {
435
- fmt ! ( "'%s:%?" ,
436
- str :: from_bytes( [ ( 'a' as u8 ) + ( id as u8 ) ] ) ,
437
- did)
443
+ fmt ! ( "%c:%?" , parm, did)
438
444
} else {
439
- fmt ! ( "'%s" ,
440
- str :: from_bytes( [ ( 'a' as u8 ) + ( id as u8 ) ] ) )
445
+ fmt ! ( "%c" , parm)
441
446
}
442
447
}
443
448
ty_self( * ) => ~"Self ",
@@ -468,18 +473,20 @@ pub fn parameterized(cx: ctxt,
468
473
self_r : Option < ty:: Region > ,
469
474
tps : & [ ty:: t ] ) -> ~str {
470
475
471
- let r_str = match self_r {
472
- None => ~"",
476
+ let mut strs = ~[ ] ;
477
+ match self_r {
478
+ None => ( ) ,
473
479
Some ( r) => {
474
- region_to_str ( cx, r )
480
+ strs . push ( region_to_str ( cx, "" , false , r ) )
475
481
}
476
482
} ;
477
483
478
- if tps. len ( ) > 0 u {
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 ( ) > 0 u {
487
+ fmt ! ( "%s<%s>" , base, strs. connect( "," ) )
481
488
} else {
482
- fmt ! ( "%s%s" , r_str , base)
489
+ fmt ! ( "%s" , base)
483
490
}
484
491
}
485
492
@@ -597,7 +604,7 @@ impl Repr for @ast::pat {
597
604
598
605
impl Repr for ty:: Region {
599
606
fn repr ( & self , tcx : ctxt ) -> ~str {
600
- region_to_str ( tcx, * self )
607
+ region_to_str ( tcx, "" , false , * self )
601
608
}
602
609
}
603
610
0 commit comments