diff options
| author | bors <bors@rust-lang.org> | 2013-08-19 01:42:05 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-19 01:42:05 -0700 |
| commit | 3e4f40ec5aee04c0e5386153644255b6beeba095 (patch) | |
| tree | 76c18bfe4ce322f612b63f103bdc89d99eab00c2 /src/libsyntax | |
| parent | c178b52fe594c6724d0cf9124665de7e627899a9 (diff) | |
| parent | 22c7bbfd0c49330015e24adeb0f2c45ae669c29f (diff) | |
| download | rust-3e4f40ec5aee04c0e5386153644255b6beeba095.tar.gz rust-3e4f40ec5aee04c0e5386153644255b6beeba095.zip | |
auto merge of #8564 : alexcrichton/rust/ifmt+++, r=graydon
See discussion in #8489, but this selects option 3 by adding a `Default` trait to be implemented by various basic types.
Once this makes it into a snapshot I think it's about time to start overhauling all current use-cases of `fmt!` to move towards `ifmt!`. The goal is to replace `%X` with `{}` in 90% of situations, and this commit should enable that.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/ifmt.rs | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index 6999f046b7b..35be77b95c5 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -623,19 +623,16 @@ impl Context { fn format_arg(&self, sp: span, arg: Either<uint, @str>, ident: ast::ident) -> @ast::expr { - let mut ty = match arg { + let ty = match arg { Left(i) => self.arg_types[i].unwrap(), Right(s) => *self.name_types.get(&s) }; - // Default types to '?' if nothing else is specified. - if ty == Unknown { - ty = Known(@"?"); - } let argptr = self.ecx.expr_addr_of(sp, self.ecx.expr_ident(sp, ident)); - match ty { + let fmt_trait = match ty { + Unknown => "Default", Known(tyname) => { - let fmt_trait = match tyname.as_slice() { + match tyname.as_slice() { "?" => "Poly", "b" => "Bool", "c" => "Char", @@ -653,35 +650,35 @@ impl Context { `%s`", tyname)); "Dummy" } - }; - let format_fn = self.ecx.path_global(sp, ~[ - self.ecx.ident_of("std"), - self.ecx.ident_of("fmt"), - self.ecx.ident_of(fmt_trait), - self.ecx.ident_of("fmt"), - ]); - self.ecx.expr_call_global(sp, ~[ - self.ecx.ident_of("std"), - self.ecx.ident_of("fmt"), - self.ecx.ident_of("argument"), - ], ~[self.ecx.expr_path(format_fn), argptr]) + } } String => { - self.ecx.expr_call_global(sp, ~[ + return self.ecx.expr_call_global(sp, ~[ self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), self.ecx.ident_of("argumentstr"), ], ~[argptr]) } Unsigned => { - self.ecx.expr_call_global(sp, ~[ + return self.ecx.expr_call_global(sp, ~[ self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), self.ecx.ident_of("argumentuint"), ], ~[argptr]) } - Unknown => { fail!() } - } + }; + + let format_fn = self.ecx.path_global(sp, ~[ + self.ecx.ident_of("std"), + self.ecx.ident_of("fmt"), + self.ecx.ident_of(fmt_trait), + self.ecx.ident_of("fmt"), + ]); + self.ecx.expr_call_global(sp, ~[ + self.ecx.ident_of("std"), + self.ecx.ident_of("fmt"), + self.ecx.ident_of("argument"), + ], ~[self.ecx.expr_path(format_fn), argptr]) } } |
