@@ -250,8 +250,8 @@ pub trait UpperExp for Sized? {
250
250
fn fmt ( & self , & mut Formatter ) -> Result ;
251
251
}
252
252
253
- // FIXME #11938 - UFCS would make us able call the above methods
254
- // directly Show::show(x, fmt).
253
+ // NOTE(stage0): Remove macro after next snapshot
254
+ # [ cfg ( stage0 ) ]
255
255
macro_rules! uniform_fn_call_workaround {
256
256
( $( $name: ident, $trait_: ident; ) * ) => {
257
257
$(
@@ -262,6 +262,8 @@ macro_rules! uniform_fn_call_workaround {
262
262
) *
263
263
}
264
264
}
265
+ // NOTE(stage0): Remove macro after next snapshot
266
+ #[ cfg( stage0) ]
265
267
uniform_fn_call_workaround ! {
266
268
secret_show, Show ;
267
269
secret_bool, Bool ;
@@ -568,36 +570,65 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
568
570
569
571
/// When the compiler determines that the type of an argument *must* be a string
570
572
/// (such as for select), then it invokes this method.
573
+ // NOTE(stage0): remove function after a snapshot
574
+ #[ cfg( stage0) ]
571
575
#[ doc( hidden) ] #[ inline]
572
576
pub fn argumentstr < ' a > ( s : & ' a & str ) -> Argument < ' a > {
573
577
argument ( secret_string, s)
574
578
}
575
579
580
+ /// When the compiler determines that the type of an argument *must* be a string
581
+ /// (such as for select), then it invokes this method.
582
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
583
+ #[ doc( hidden) ] #[ inline]
584
+ pub fn argumentstr < ' a > ( s : & ' a & str ) -> Argument < ' a > {
585
+ argument ( String :: fmt, s)
586
+ }
587
+
576
588
/// When the compiler determines that the type of an argument *must* be a uint
577
589
/// (such as for plural), then it invokes this method.
590
+ // NOTE(stage0): remove function after a snapshot
591
+ #[ cfg( stage0) ]
578
592
#[ doc( hidden) ] #[ inline]
579
593
pub fn argumentuint < ' a > ( s : & ' a uint ) -> Argument < ' a > {
580
594
argument ( secret_unsigned, s)
581
595
}
582
596
597
+ /// When the compiler determines that the type of an argument *must* be a uint
598
+ /// (such as for plural), then it invokes this method.
599
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
600
+ #[ doc( hidden) ] #[ inline]
601
+ pub fn argumentuint < ' a > ( s : & ' a uint ) -> Argument < ' a > {
602
+ argument ( Unsigned :: fmt, s)
603
+ }
604
+
583
605
// Implementations of the core formatting traits
584
606
585
607
impl < ' a , Sized ? T : Show > Show for & ' a T {
586
- fn fmt ( & self , f : & mut Formatter ) -> Result { secret_show ( * self , f) }
608
+ fn fmt ( & self , f : & mut Formatter ) -> Result { ( * * self ) . fmt ( f) }
587
609
}
588
610
impl < ' a , Sized ? T : Show > Show for & ' a mut T {
589
- fn fmt ( & self , f : & mut Formatter ) -> Result { secret_show ( & * * self , f) }
611
+ fn fmt ( & self , f : & mut Formatter ) -> Result { ( * * self ) . fmt ( f) }
590
612
}
591
613
impl < ' a > Show for & ' a Show +' a {
592
614
fn fmt ( & self , f : & mut Formatter ) -> Result { ( * self ) . fmt ( f) }
593
615
}
594
616
617
+ // NOTE(stage0): remove impl after a snapshot
618
+ #[ cfg( stage0) ]
595
619
impl Bool for bool {
596
620
fn fmt ( & self , f : & mut Formatter ) -> Result {
597
621
secret_string ( & ( if * self { "true" } else { "false" } ) , f)
598
622
}
599
623
}
600
624
625
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
626
+ impl Bool for bool {
627
+ fn fmt ( & self , f : & mut Formatter ) -> Result {
628
+ String :: fmt ( if * self { "true" } else { "false" } , f)
629
+ }
630
+ }
631
+
601
632
impl < T : str:: Str > String for T {
602
633
fn fmt ( & self , f : & mut Formatter ) -> Result {
603
634
f. pad ( self . as_slice ( ) )
@@ -610,6 +641,8 @@ impl String for str {
610
641
}
611
642
}
612
643
644
+ // NOTE(stage0): remove impl after a snapshot
645
+ #[ cfg( stage0) ]
613
646
impl Char for char {
614
647
fn fmt ( & self , f : & mut Formatter ) -> Result {
615
648
use char:: Char ;
@@ -621,28 +654,80 @@ impl Char for char {
621
654
}
622
655
}
623
656
657
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
658
+ impl Char for char {
659
+ fn fmt ( & self , f : & mut Formatter ) -> Result {
660
+ use char:: Char ;
661
+
662
+ let mut utf8 = [ 0u8 , ..4 ] ;
663
+ let amt = self . encode_utf8 ( utf8) . unwrap_or ( 0 ) ;
664
+ let s: & str = unsafe { mem:: transmute ( utf8[ ..amt] ) } ;
665
+ String :: fmt ( s, f)
666
+ }
667
+ }
668
+
669
+ // NOTE(stage0): remove impl after a snapshot
670
+ #[ cfg( stage0) ]
624
671
impl < T > Pointer for * const T {
625
672
fn fmt ( & self , f : & mut Formatter ) -> Result {
626
673
f. flags |= 1 << ( rt:: FlagAlternate as uint ) ;
627
674
secret_lower_hex :: < uint > ( & ( * self as uint ) , f)
628
675
}
629
676
}
677
+
678
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
679
+ impl < T > Pointer for * const T {
680
+ fn fmt ( & self , f : & mut Formatter ) -> Result {
681
+ f. flags |= 1 << ( rt:: FlagAlternate as uint ) ;
682
+ LowerHex :: fmt ( & ( * self as uint ) , f)
683
+ }
684
+ }
685
+
686
+ // NOTE(stage0): remove impl after a snapshot
687
+ #[ cfg( stage0) ]
630
688
impl < T > Pointer for * mut T {
631
689
fn fmt ( & self , f : & mut Formatter ) -> Result {
632
690
secret_pointer :: < * const T > ( & ( * self as * const T ) , f)
633
691
}
634
692
}
693
+
694
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
695
+ impl < T > Pointer for * mut T {
696
+ fn fmt ( & self , f : & mut Formatter ) -> Result {
697
+ Pointer :: fmt ( & ( * self as * const T ) , f)
698
+ }
699
+ }
700
+
701
+ // NOTE(stage0): remove impl after a snapshot
702
+ #[ cfg( stage0) ]
635
703
impl < ' a , T > Pointer for & ' a T {
636
704
fn fmt ( & self , f : & mut Formatter ) -> Result {
637
705
secret_pointer :: < * const T > ( & ( & * * self as * const T ) , f)
638
706
}
639
707
}
708
+
709
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
710
+ impl < ' a , T > Pointer for & ' a T {
711
+ fn fmt ( & self , f : & mut Formatter ) -> Result {
712
+ Pointer :: fmt ( & ( * self as * const T ) , f)
713
+ }
714
+ }
715
+
716
+ // NOTE(stage0): remove impl after a snapshot
717
+ #[ cfg( stage0) ]
640
718
impl < ' a , T > Pointer for & ' a mut T {
641
719
fn fmt ( & self , f : & mut Formatter ) -> Result {
642
720
secret_pointer :: < * const T > ( & ( & * * self as * const T ) , f)
643
721
}
644
722
}
645
723
724
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
725
+ impl < ' a , T > Pointer for & ' a mut T {
726
+ fn fmt ( & self , f : & mut Formatter ) -> Result {
727
+ Pointer :: fmt ( & ( & * * self as * const T ) , f)
728
+ }
729
+ }
730
+
646
731
macro_rules! floating( ( $ty: ident) => {
647
732
impl Float for $ty {
648
733
fn fmt( & self , fmt: & mut Formatter ) -> Result {
@@ -712,26 +797,69 @@ floating!(f64)
712
797
713
798
// Implementation of Show for various core types
714
799
800
+ // NOTE(stage0): remove macro after a snapshot
801
+ #[ cfg( stage0) ]
715
802
macro_rules! delegate( ( $ty: ty to $other: ident) => {
716
803
impl Show for $ty {
717
804
fn fmt( & self , f: & mut Formatter ) -> Result {
718
805
( concat_idents!( secret_, $other) ( self , f) )
719
806
}
720
807
}
721
808
} )
809
+
810
+ // NOTE(stage0): remove these macros after a snapshot
811
+ #[ cfg( stage0) ]
722
812
delegate ! ( str to string)
813
+ #[ cfg( stage0) ]
723
814
delegate ! ( bool to bool )
815
+ #[ cfg( stage0) ]
724
816
delegate ! ( char to char )
817
+ #[ cfg( stage0) ]
725
818
delegate ! ( f32 to float)
819
+ #[ cfg( stage0) ]
726
820
delegate ! ( f64 to float)
727
821
822
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
823
+ macro_rules! delegate( ( $ty: ty to $other: ident) => {
824
+ impl Show for $ty {
825
+ fn fmt( & self , f: & mut Formatter ) -> Result {
826
+ $other:: fmt( self , f)
827
+ }
828
+ }
829
+ } )
830
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
831
+ delegate ! ( str to String )
832
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
833
+ delegate ! ( bool to Bool )
834
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
835
+ delegate ! ( char to Char )
836
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
837
+ delegate ! ( f32 to Float )
838
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
839
+ delegate ! ( f64 to Float )
840
+
841
+ // NOTE(stage0): remove impl after a snapshot
842
+ #[ cfg( stage0) ]
728
843
impl < T > Show for * const T {
729
844
fn fmt ( & self , f : & mut Formatter ) -> Result { secret_pointer ( self , f) }
730
845
}
846
+
847
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
848
+ impl < T > Show for * const T {
849
+ fn fmt ( & self , f : & mut Formatter ) -> Result { Pointer :: fmt ( self , f) }
850
+ }
851
+
852
+ // NOTE(stage0): remove impl after a snapshot
853
+ #[ cfg( stage0) ]
731
854
impl < T > Show for * mut T {
732
855
fn fmt ( & self , f : & mut Formatter ) -> Result { secret_pointer ( self , f) }
733
856
}
734
857
858
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): remove cfg after a snapshot
859
+ impl < T > Show for * mut T {
860
+ fn fmt ( & self , f : & mut Formatter ) -> Result { Pointer :: fmt ( self , f) }
861
+ }
862
+
735
863
macro_rules! peel( ( $name: ident, $( $other: ident, ) * ) => ( tuple!( $( $other, ) * ) ) )
736
864
737
865
macro_rules! tuple (
0 commit comments