Skip to content

Commit 41ffc90

Browse files
committed
auto merge of #10187 : pcwalton/rust/remove-mocks, r=pcwalton
r? @alexcrichton
2 parents 1bbd4af + a6f776d commit 41ffc90

File tree

13 files changed

+451
-238
lines changed

13 files changed

+451
-238
lines changed

src/librustc/util/ppaux.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,11 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
308308
ident: Option<ast::Ident>,
309309
sig: &ty::FnSig)
310310
-> ~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+
};
315316

316317
match purity {
317318
ast::impure_fn => {}
@@ -331,16 +332,16 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
331332
_ => { }
332333
}
333334

334-
push_sig_to_str(cx, &mut s, sig);
335+
push_sig_to_str(cx, &mut s, '(', ')', sig);
335336

336337
return s;
337338
}
338-
fn closure_to_str(cx: ctxt, cty: &ty::ClosureTy) -> ~str
339-
{
339+
fn closure_to_str(cx: ctxt, cty: &ty::ClosureTy) -> ~str {
340340
let is_proc =
341341
(cty.sigil, cty.onceness) == (ast::OwnedSigil, ast::Once);
342+
let is_borrowed_closure = cty.sigil == ast::BorrowedSigil;
342343

343-
let mut s = if is_proc {
344+
let mut s = if is_proc || is_borrowed_closure {
344345
~""
345346
} else {
346347
cty.sigil.to_str()
@@ -374,23 +375,42 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
374375
}
375376
};
376377

377-
s.push_str("fn");
378+
if !is_borrowed_closure {
379+
s.push_str("fn");
380+
}
378381
}
379382

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);
384394

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+
}
386402

387403
return s;
388404
}
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);
391411
let strs = sig.inputs.map(|a| fn_input_to_str(cx, *a));
392412
s.push_str(strs.connect(", "));
393-
s.push_char(')');
413+
s.push_char(ket);
394414
if ty::get(sig.output).sty != ty_nil {
395415
s.push_str(" -> ");
396416
if ty::type_is_bot(sig.output) {

0 commit comments

Comments
 (0)