Skip to content

Commit 5f3ef02

Browse files
committed
---
yaml --- r: 103801 b: refs/heads/try c: d8b6919 h: refs/heads/master i: 103799: e8d0535 v: v3
1 parent e12860e commit 5f3ef02

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
5-
refs/heads/try: 003ce502350ed1e374b740ee2d719e500c165615
5+
refs/heads/try: d8b6919d4fcd1b69494278bb4472e095e2cd52f3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/fmt/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,41 @@ pub trait LowerExp { fn fmt(&Self, &mut Formatter); }
606606
#[allow(missing_doc)]
607607
pub trait UpperExp { fn fmt(&Self, &mut Formatter); }
608608

609+
// FIXME #11938 - UFCS would make us able call the above methods
610+
// directly Show::show(x, fmt).
611+
612+
// FIXME(huonw's WIP): this is a intermediate state waiting for a
613+
// snapshot (at the time of writing we're at 2014-01-20 b6400f9), to
614+
// be able to make the `fmt` functions into normal methods and have
615+
// `format!()` still work.
616+
macro_rules! uniform_fn_call_workaround {
617+
($( $name: ident, $trait_: ident; )*) => {
618+
$(
619+
#[doc(hidden)]
620+
pub fn $name<T: $trait_>(x: &T, fmt: &mut Formatter) {
621+
$trait_::fmt(x, fmt)
622+
}
623+
)*
624+
}
625+
}
626+
uniform_fn_call_workaround! {
627+
secret_show, Show;
628+
secret_bool, Bool;
629+
secret_char, Char;
630+
secret_signed, Signed;
631+
secret_unsigned, Unsigned;
632+
secret_octal, Octal;
633+
secret_binary, Binary;
634+
secret_lower_hex, LowerHex;
635+
secret_upper_hex, UpperHex;
636+
secret_string, String;
637+
secret_poly, Poly;
638+
secret_pointer, Pointer;
639+
secret_float, Float;
640+
secret_lower_exp, LowerExp;
641+
secret_upper_exp, UpperExp;
642+
}
643+
609644
/// The `write` function takes an output stream, a precompiled format string,
610645
/// and a list of arguments. The arguments will be formatted according to the
611646
/// specified format string into the output stream provided.

branches/try/src/libsyntax/ext/format.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'a> Context<'a> {
702702
Named(ref s) => self.name_types.get(s)
703703
};
704704

705-
let fmt_trait = match *ty {
705+
let fmt_fn = match *ty {
706706
Known(ref tyname) => {
707707
match tyname.as_slice() {
708708
"" => "secret_show",
@@ -721,10 +721,9 @@ impl<'a> Context<'a> {
721721
"x" => "secret_lower_hex",
722722
"X" => "secret_upper_hex",
723723
_ => {
724-
self.ecx.span_err(sp,
725-
format!("unknown format trait `{}`",
726-
*tyname));
727-
"Dummy"
724+
self.ecx.span_err(sp, format!("unknown format trait `{}`",
725+
*tyname));
726+
"dummy"
728727
}
729728
}
730729
}
@@ -747,8 +746,7 @@ impl<'a> Context<'a> {
747746
let format_fn = self.ecx.path_global(sp, ~[
748747
self.ecx.ident_of("std"),
749748
self.ecx.ident_of("fmt"),
750-
self.ecx.ident_of(fmt_trait),
751-
self.ecx.ident_of("fmt"),
749+
self.ecx.ident_of(fmt_fn),
752750
]);
753751
self.ecx.expr_call_global(sp, ~[
754752
self.ecx.ident_of("std"),

0 commit comments

Comments
 (0)