@@ -308,10 +308,11 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
308
308
ident : Option < ast:: Ident > ,
309
309
sig : & ty:: FnSig )
310
310
-> ~str {
311
- let mut s = ~"extern ";
312
-
313
- s.push_str(abis.to_str());
314
- s.push_char(' ');
311
+ let mut s = if abis. is_rust ( ) {
312
+ ~""
313
+ } else {
314
+ format ! ( "extern {} " , abis. to_str( ) )
315
+ } ;
315
316
316
317
match purity {
317
318
ast:: impure_fn => { }
@@ -331,16 +332,16 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
331
332
_ => { }
332
333
}
333
334
334
- push_sig_to_str ( cx, & mut s, sig) ;
335
+ push_sig_to_str ( cx, & mut s, '(' , ')' , sig) ;
335
336
336
337
return s;
337
338
}
338
- fn closure_to_str ( cx : ctxt , cty : & ty:: ClosureTy ) -> ~str
339
- {
339
+ fn closure_to_str ( cx : ctxt , cty : & ty:: ClosureTy ) -> ~str {
340
340
let is_proc =
341
341
( cty. sigil , cty. onceness ) == ( ast:: OwnedSigil , ast:: Once ) ;
342
+ let is_borrowed_closure = cty. sigil == ast:: BorrowedSigil ;
342
343
343
- let mut s = if is_proc {
344
+ let mut s = if is_proc || is_borrowed_closure {
344
345
~""
345
346
} else {
346
347
cty. sigil . to_str ( )
@@ -374,23 +375,42 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
374
375
}
375
376
} ;
376
377
377
- s. push_str ( "fn" ) ;
378
+ if !is_borrowed_closure {
379
+ s. push_str ( "fn" ) ;
380
+ }
378
381
}
379
382
380
- if !cty. bounds . is_empty ( ) {
381
- s. push_str ( ":" ) ;
382
- }
383
- s. push_str ( cty. bounds . repr ( cx) ) ;
383
+ if !is_borrowed_closure {
384
+ // Print bounds before `fn` if this is not a borrowed closure.
385
+ if !cty. bounds . is_empty ( ) {
386
+ s. push_str ( ":" ) ;
387
+ s. push_str ( cty. bounds . repr ( cx) ) ;
388
+ }
389
+
390
+ push_sig_to_str ( cx, & mut s, '(' , ')' , & cty. sig ) ;
391
+ } else {
392
+ // Print bounds after the signature if this is a borrowed closure.
393
+ push_sig_to_str ( cx, & mut s, '|' , '|' , & cty. sig ) ;
384
394
385
- push_sig_to_str ( cx, & mut s, & cty. sig ) ;
395
+ if is_borrowed_closure {
396
+ if !cty. bounds . is_empty ( ) {
397
+ s. push_str ( ":" ) ;
398
+ s. push_str ( cty. bounds . repr ( cx) ) ;
399
+ }
400
+ }
401
+ }
386
402
387
403
return s;
388
404
}
389
- fn push_sig_to_str ( cx : ctxt , s : & mut ~str , sig : & ty:: FnSig ) {
390
- s. push_char ( '(' ) ;
405
+ fn push_sig_to_str ( cx : ctxt ,
406
+ s : & mut ~str ,
407
+ bra : char ,
408
+ ket : char ,
409
+ sig : & ty:: FnSig ) {
410
+ s. push_char ( bra) ;
391
411
let strs = sig. inputs . map ( |a| fn_input_to_str ( cx, * a) ) ;
392
412
s. push_str ( strs. connect ( ", " ) ) ;
393
- s. push_char ( ')' ) ;
413
+ s. push_char ( ket ) ;
394
414
if ty:: get ( sig. output ) . sty != ty_nil {
395
415
s. push_str ( " -> " ) ;
396
416
if ty:: type_is_bot ( sig. output ) {
0 commit comments