diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-08-14 20:40:15 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-08-16 16:09:33 -0700 |
| commit | 22c7bbfd0c49330015e24adeb0f2c45ae669c29f (patch) | |
| tree | 44c61eb2f97f4a828c691db400dffdf17765c911 /src/libsyntax | |
| parent | 109274426a7cd676b9aa1bb06afd9f86b44f6e9b (diff) | |
| download | rust-22c7bbfd0c49330015e24adeb0f2c45ae669c29f.tar.gz rust-22c7bbfd0c49330015e24adeb0f2c45ae669c29f.zip | |
Delegate `{}` to Default instead of Poly
By using a separate trait this is overridable on a per-type basis and makes room for the possibility of even more arguments passed in for the future.
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]) } } |
