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
This commit is contained in:
Marijn Haverbeke 2012-01-16 11:32:38 +01:00
parent e1c50c4410
commit c2fe7b6398
4 changed files with 13 additions and 5 deletions

View file

@ -22,8 +22,16 @@ fn mode_str(m: ty::mode) -> str {
fn ty_to_str(cx: ctxt, typ: t) -> str { fn ty_to_str(cx: ctxt, typ: t) -> str {
fn fn_input_to_str(cx: ctxt, input: {mode: middle::ty::mode, ty: t}) -> fn fn_input_to_str(cx: ctxt, input: {mode: middle::ty::mode, ty: t}) ->
str { str {
let s = mode_str(input.mode); let modestr = alt input.mode {
ret s + ty_to_str(cx, input.ty); 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>, fn fn_to_str(cx: ctxt, proto: ast::proto, ident: option::t<ast::ident>,
inputs: [arg], output: t, cf: ast::ret_style, inputs: [arg], output: t, cf: ast::ret_style,

View file

@ -2,5 +2,5 @@ fn main() {
fn f() { } fn f() { }
fn g(i: int) { } fn g(i: int) { }
let x = f == g; let x = f == g;
//!^ ERROR expected `native fn()` but found `native fn(++int)` //!^ ERROR expected `native fn()` but found `native fn(int)`
} }

View file

@ -1,3 +1,3 @@
fn main(foo: {x: int, y: int}) { 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})`
} }

View file

@ -4,5 +4,5 @@ fn test(f: fn@(uint) -> uint) -> uint {
fn main() { fn main() {
let f = fn~(x: uint) -> uint { ret 4u; }; 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`
} }