Skip to content

Commit c2fe7b6

Browse files
committed
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
1 parent e1c50c4 commit c2fe7b6

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/comp/util/ppaux.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ fn mode_str(m: ty::mode) -> str {
2222
fn ty_to_str(cx: ctxt, typ: t) -> str {
2323
fn fn_input_to_str(cx: ctxt, input: {mode: middle::ty::mode, ty: t}) ->
2424
str {
25-
let s = mode_str(input.mode);
26-
ret s + ty_to_str(cx, input.ty);
25+
let modestr = alt input.mode {
26+
ast::by_ref. {
27+
ty::type_is_immediate(cx, input.ty) ? "&&" : ""
28+
}
29+
ast::by_val. {
30+
ty::type_is_immediate(cx, input.ty) ? "" : "++"
31+
}
32+
_ { mode_str(input.mode) }
33+
};
34+
modestr + ty_to_str(cx, input.ty)
2735
}
2836
fn fn_to_str(cx: ctxt, proto: ast::proto, ident: option::t<ast::ident>,
2937
inputs: [arg], output: t, cf: ast::ret_style,

src/test/compile-fail/fn-compare-mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ fn main() {
22
fn f() { }
33
fn g(i: int) { }
44
let x = f == g;
5-
//!^ ERROR expected `native fn()` but found `native fn(++int)`
5+
//!^ ERROR expected `native fn()` but found `native fn(int)`
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main(foo: {x: int, y: int}) {
2-
//!^ ERROR wrong type in main function: found `native fn(&&{x: int,y: int})`
2+
//!^ ERROR wrong type in main function: found `native fn({x: int,y: int})`
33
}

src/test/compile-fail/sendfn-is-not-a-lambda.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn test(f: fn@(uint) -> uint) -> uint {
44

55
fn main() {
66
let f = fn~(x: uint) -> uint { ret 4u; };
7-
log(debug, test(f)); //! ERROR expected `fn@(++uint) -> uint`
7+
log(debug, test(f)); //! ERROR expected `fn@(uint) -> uint`
88
}

0 commit comments

Comments
 (0)