Skip to content

Commit ebc9cb6

Browse files
committed
---
yaml --- r: 148823 b: refs/heads/try2 c: d8b6919 h: refs/heads/master i: 148821: 7c2a0b5 148819: ac84fcc 148815: f0c39a8 v: v3
1 parent 03bacd3 commit ebc9cb6

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 003ce502350ed1e374b740ee2d719e500c165615
8+
refs/heads/try2: d8b6919d4fcd1b69494278bb4472e095e2cd52f3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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)