From 22c7bbfd0c49330015e24adeb0f2c45ae669c29f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 14 Aug 2013 20:40:15 -0700 Subject: 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. --- src/libsyntax/ext/ifmt.rs | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/libsyntax') 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, 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]) } } -- cgit 1.4.1-3-g733a5