Skip to content

Commit 386cc76

Browse files
committed
rollup merge of rust-lang#18537 : japaric/no-secret
2 parents a8fdcc3 + 3a075dc commit 386cc76

File tree

3 files changed

+157
-22
lines changed

3 files changed

+157
-22
lines changed

src/libcore/fmt/mod.rs

Lines changed: 132 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ pub trait UpperExp for Sized? {
250250
fn fmt(&self, &mut Formatter) -> Result;
251251
}
252252

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)]
255255
macro_rules! uniform_fn_call_workaround {
256256
($( $name: ident, $trait_: ident; )*) => {
257257
$(
@@ -262,6 +262,8 @@ macro_rules! uniform_fn_call_workaround {
262262
)*
263263
}
264264
}
265+
// NOTE(stage0): Remove macro after next snapshot
266+
#[cfg(stage0)]
265267
uniform_fn_call_workaround! {
266268
secret_show, Show;
267269
secret_bool, Bool;
@@ -568,36 +570,65 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
568570

569571
/// When the compiler determines that the type of an argument *must* be a string
570572
/// (such as for select), then it invokes this method.
573+
// NOTE(stage0): remove function after a snapshot
574+
#[cfg(stage0)]
571575
#[doc(hidden)] #[inline]
572576
pub fn argumentstr<'a>(s: &'a &str) -> Argument<'a> {
573577
argument(secret_string, s)
574578
}
575579

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+
576588
/// When the compiler determines that the type of an argument *must* be a uint
577589
/// (such as for plural), then it invokes this method.
590+
// NOTE(stage0): remove function after a snapshot
591+
#[cfg(stage0)]
578592
#[doc(hidden)] #[inline]
579593
pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
580594
argument(secret_unsigned, s)
581595
}
582596

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+
583605
// Implementations of the core formatting traits
584606

585607
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) }
587609
}
588610
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) }
590612
}
591613
impl<'a> Show for &'a Show+'a {
592614
fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
593615
}
594616

617+
// NOTE(stage0): remove impl after a snapshot
618+
#[cfg(stage0)]
595619
impl Bool for bool {
596620
fn fmt(&self, f: &mut Formatter) -> Result {
597621
secret_string(&(if *self {"true"} else {"false"}), f)
598622
}
599623
}
600624

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+
601632
impl<T: str::Str> String for T {
602633
fn fmt(&self, f: &mut Formatter) -> Result {
603634
f.pad(self.as_slice())
@@ -610,6 +641,8 @@ impl String for str {
610641
}
611642
}
612643

644+
// NOTE(stage0): remove impl after a snapshot
645+
#[cfg(stage0)]
613646
impl Char for char {
614647
fn fmt(&self, f: &mut Formatter) -> Result {
615648
use char::Char;
@@ -621,28 +654,80 @@ impl Char for char {
621654
}
622655
}
623656

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)]
624671
impl<T> Pointer for *const T {
625672
fn fmt(&self, f: &mut Formatter) -> Result {
626673
f.flags |= 1 << (rt::FlagAlternate as uint);
627674
secret_lower_hex::<uint>(&(*self as uint), f)
628675
}
629676
}
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)]
630688
impl<T> Pointer for *mut T {
631689
fn fmt(&self, f: &mut Formatter) -> Result {
632690
secret_pointer::<*const T>(&(*self as *const T), f)
633691
}
634692
}
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)]
635703
impl<'a, T> Pointer for &'a T {
636704
fn fmt(&self, f: &mut Formatter) -> Result {
637705
secret_pointer::<*const T>(&(&**self as *const T), f)
638706
}
639707
}
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)]
640718
impl<'a, T> Pointer for &'a mut T {
641719
fn fmt(&self, f: &mut Formatter) -> Result {
642720
secret_pointer::<*const T>(&(&**self as *const T), f)
643721
}
644722
}
645723

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+
646731
macro_rules! floating(($ty:ident) => {
647732
impl Float for $ty {
648733
fn fmt(&self, fmt: &mut Formatter) -> Result {
@@ -712,26 +797,69 @@ floating!(f64)
712797

713798
// Implementation of Show for various core types
714799

800+
// NOTE(stage0): remove macro after a snapshot
801+
#[cfg(stage0)]
715802
macro_rules! delegate(($ty:ty to $other:ident) => {
716803
impl Show for $ty {
717804
fn fmt(&self, f: &mut Formatter) -> Result {
718805
(concat_idents!(secret_, $other)(self, f))
719806
}
720807
}
721808
})
809+
810+
// NOTE(stage0): remove these macros after a snapshot
811+
#[cfg(stage0)]
722812
delegate!(str to string)
813+
#[cfg(stage0)]
723814
delegate!(bool to bool)
815+
#[cfg(stage0)]
724816
delegate!(char to char)
817+
#[cfg(stage0)]
725818
delegate!(f32 to float)
819+
#[cfg(stage0)]
726820
delegate!(f64 to float)
727821

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)]
728843
impl<T> Show for *const T {
729844
fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
730845
}
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)]
731854
impl<T> Show for *mut T {
732855
fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
733856
}
734857

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+
735863
macro_rules! peel(($name:ident, $($other:ident,)*) => (tuple!($($other,)*)))
736864

737865
macro_rules! tuple (

src/libstd/fmt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,20 @@ pub use core::fmt::{Argument, Arguments, write, radix, Radix, RadixFmt};
424424

425425
#[doc(hidden)]
426426
pub use core::fmt::{argument, argumentstr, argumentuint};
427+
// NOTE(stage0): remove these imports after a snapshot
428+
#[cfg(stage0)]
427429
#[doc(hidden)]
428430
pub use core::fmt::{secret_show, secret_string, secret_unsigned};
431+
#[cfg(stage0)]
429432
#[doc(hidden)]
430433
pub use core::fmt::{secret_signed, secret_lower_hex, secret_upper_hex};
434+
#[cfg(stage0)]
431435
#[doc(hidden)]
432436
pub use core::fmt::{secret_bool, secret_char, secret_octal, secret_binary};
437+
#[cfg(stage0)]
433438
#[doc(hidden)]
434439
pub use core::fmt::{secret_float, secret_upper_exp, secret_lower_exp};
440+
#[cfg(stage0)]
435441
#[doc(hidden)]
436442
pub use core::fmt::{secret_pointer};
437443

src/libsyntax/ext/format.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -663,28 +663,28 @@ impl<'a, 'b> Context<'a, 'b> {
663663
fn format_arg(ecx: &ExtCtxt, sp: Span,
664664
ty: &ArgumentType, arg: P<ast::Expr>)
665665
-> P<ast::Expr> {
666-
let (krate, fmt_fn) = match *ty {
666+
let trait_ = match *ty {
667667
Known(ref tyname) => {
668668
match tyname.as_slice() {
669-
"" => ("std", "secret_show"),
670-
"b" => ("std", "secret_bool"),
671-
"c" => ("std", "secret_char"),
672-
"d" | "i" => ("std", "secret_signed"),
673-
"e" => ("std", "secret_lower_exp"),
674-
"E" => ("std", "secret_upper_exp"),
675-
"f" => ("std", "secret_float"),
676-
"o" => ("std", "secret_octal"),
677-
"p" => ("std", "secret_pointer"),
678-
"s" => ("std", "secret_string"),
679-
"t" => ("std", "secret_binary"),
680-
"u" => ("std", "secret_unsigned"),
681-
"x" => ("std", "secret_lower_hex"),
682-
"X" => ("std", "secret_upper_hex"),
669+
"" => "Show",
670+
"b" => "Bool",
671+
"c" => "Char",
672+
"d" | "i" => "Signed",
673+
"e" => "LowerExp",
674+
"E" => "UpperExp",
675+
"f" => "Float",
676+
"o" => "Octal",
677+
"p" => "Pointer",
678+
"s" => "String",
679+
"t" => "Binary",
680+
"u" => "Unsigned",
681+
"x" => "LowerHex",
682+
"X" => "UpperHex",
683683
_ => {
684684
ecx.span_err(sp,
685685
format!("unknown format trait `{}`",
686686
*tyname).as_slice());
687-
("std", "dummy")
687+
"Dummy"
688688
}
689689
}
690690
}
@@ -697,9 +697,10 @@ impl<'a, 'b> Context<'a, 'b> {
697697
};
698698

699699
let format_fn = ecx.path_global(sp, vec![
700-
ecx.ident_of(krate),
700+
ecx.ident_of("std"),
701701
ecx.ident_of("fmt"),
702-
ecx.ident_of(fmt_fn)]);
702+
ecx.ident_of(trait_),
703+
ecx.ident_of("fmt")]);
703704
ecx.expr_call_global(sp, vec![
704705
ecx.ident_of("std"),
705706
ecx.ident_of("fmt"),

0 commit comments

Comments
 (0)