about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-16 11:32:38 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-16 12:08:00 +0100
commitc2fe7b63985ce8ec0a85adfa47e3c2d8f5b6dc3b (patch)
tree2b0961905ff53913e8933a658a4dc376508a5bbb
parente1c50c4410804dfce9fbe040f341f6104cc9ba7e (diff)
downloadrust-c2fe7b63985ce8ec0a85adfa47e3c2d8f5b6dc3b.tar.gz
rust-c2fe7b63985ce8ec0a85adfa47e3c2d8f5b6dc3b.zip
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
-rw-r--r--src/comp/util/ppaux.rs12
-rw-r--r--src/test/compile-fail/fn-compare-mismatch.rs2
-rw-r--r--src/test/compile-fail/main-wrong-type.rs2
-rw-r--r--src/test/compile-fail/sendfn-is-not-a-lambda.rs2
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<ast::ident>,
                  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`
 }