From c2fe7b63985ce8ec0a85adfa47e3c2d8f5b6dc3b Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 16 Jan 2012 11:32:38 +0100 Subject: [PATCH] When pretty-printing fn types, leave off arg modes when they are the default This reduces ++/&& spam in the output to a bare minimum. Issue #1507 --- src/comp/util/ppaux.rs | 12 ++++++++++-- src/test/compile-fail/fn-compare-mismatch.rs | 2 +- src/test/compile-fail/main-wrong-type.rs | 2 +- src/test/compile-fail/sendfn-is-not-a-lambda.rs | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs index fe6dfc4fd8a..ddab92ed861 100644 --- a/src/comp/util/ppaux.rs +++ b/src/comp/util/ppaux.rs @@ -22,8 +22,16 @@ fn mode_str(m: ty::mode) -> str { fn ty_to_str(cx: ctxt, typ: t) -> str { fn fn_input_to_str(cx: ctxt, input: {mode: middle::ty::mode, ty: t}) -> str { - let s = mode_str(input.mode); - ret s + ty_to_str(cx, input.ty); + let modestr = alt input.mode { + ast::by_ref. { + ty::type_is_immediate(cx, input.ty) ? "&&" : "" + } + ast::by_val. { + ty::type_is_immediate(cx, input.ty) ? "" : "++" + } + _ { mode_str(input.mode) } + }; + modestr + ty_to_str(cx, input.ty) } fn fn_to_str(cx: ctxt, proto: ast::proto, ident: option::t, inputs: [arg], output: t, cf: ast::ret_style, diff --git a/src/test/compile-fail/fn-compare-mismatch.rs b/src/test/compile-fail/fn-compare-mismatch.rs index a3b3e502ea4..2abf5d7b902 100644 --- a/src/test/compile-fail/fn-compare-mismatch.rs +++ b/src/test/compile-fail/fn-compare-mismatch.rs @@ -2,5 +2,5 @@ fn main() { fn f() { } fn g(i: int) { } let x = f == g; - //!^ ERROR expected `native fn()` but found `native fn(++int)` + //!^ ERROR expected `native fn()` but found `native fn(int)` } diff --git a/src/test/compile-fail/main-wrong-type.rs b/src/test/compile-fail/main-wrong-type.rs index 34f35e51e52..5cb88682597 100644 --- a/src/test/compile-fail/main-wrong-type.rs +++ b/src/test/compile-fail/main-wrong-type.rs @@ -1,3 +1,3 @@ fn main(foo: {x: int, y: int}) { -//!^ ERROR wrong type in main function: found `native fn(&&{x: int,y: int})` +//!^ ERROR wrong type in main function: found `native fn({x: int,y: int})` } diff --git a/src/test/compile-fail/sendfn-is-not-a-lambda.rs b/src/test/compile-fail/sendfn-is-not-a-lambda.rs index ca8701c692e..09d33197909 100644 --- a/src/test/compile-fail/sendfn-is-not-a-lambda.rs +++ b/src/test/compile-fail/sendfn-is-not-a-lambda.rs @@ -4,5 +4,5 @@ fn test(f: fn@(uint) -> uint) -> uint { fn main() { let f = fn~(x: uint) -> uint { ret 4u; }; - log(debug, test(f)); //! ERROR expected `fn@(++uint) -> uint` + log(debug, test(f)); //! ERROR expected `fn@(uint) -> uint` }