about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-07 20:46:30 -0800
committerbors <bors@rust-lang.org>2014-02-07 20:46:30 -0800
commitdde2e0b3865ba040261d2078db371adbefb32506 (patch)
treef7e98095e05ec7f5be10dd73f7e307f3e0921c5d /src/libstd
parent80c6c73647cc3294c587d8089d6628d8969f0b71 (diff)
parentb89afe2af7bdd9b65836b278c6e0322a8f91fb07 (diff)
downloadrust-dde2e0b3865ba040261d2078db371adbefb32506.tar.gz
rust-dde2e0b3865ba040261d2078db371adbefb32506.zip
auto merge of #12066 : huonw/rust/show2, r=alexcrichton
- Convert the formatting traits to `&self` rather than `_: &Self`
- Rejig `syntax::ext::{format,deriving}` a little in preparation
- Implement `#[deriving(Show)]`
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fmt/mod.rs154
-rw-r--r--src/libstd/io/mod.rs6
-rw-r--r--src/libstd/io/process.rs4
-rw-r--r--src/libstd/option.rs4
-rw-r--r--src/libstd/os.rs4
-rw-r--r--src/libstd/path/mod.rs4
-rw-r--r--src/libstd/result.rs4
7 files changed, 90 insertions, 90 deletions
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs
index 40ad1fb250a..d2e9fe040f7 100644
--- a/src/libstd/fmt/mod.rs
+++ b/src/libstd/fmt/mod.rs
@@ -166,11 +166,11 @@ method of the signature:
 # mod fmt { pub type Result = (); }
 # struct T;
 # trait SomeName<T> {
-fn fmt(value: &T, f: &mut std::fmt::Formatter) -> fmt::Result;
+fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result;
 # }
 ```
 
-Your type will be passed by-reference in `value`, and then the function should
+Your type will be passed as `self` by-reference, and then the function should
 emit output into the `f.buf` stream. It is up to each format trait
 implementation to correctly adhere to the requested formatting parameters. The
 values of these parameters will be listed in the fields of the `Formatter`
@@ -195,19 +195,19 @@ struct Vector2D {
 }
 
 impl fmt::Show for Vector2D {
-    fn fmt(obj: &Vector2D, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         // The `f.buf` value is of the type `&mut io::Writer`, which is what th
         // write! macro is expecting. Note that this formatting ignores the
         // various flags provided to format strings.
-        write!(f.buf, "({}, {})", obj.x, obj.y)
+        write!(f.buf, "({}, {})", self.x, self.y)
     }
 }
 
 // Different traits allow different forms of output of a type. The meaning of
 // this format is to print the magnitude of a vector.
 impl fmt::Binary for Vector2D {
-    fn fmt(obj: &Vector2D, f: &mut fmt::Formatter) -> fmt::Result {
-        let magnitude = (obj.x * obj.x + obj.y * obj.y) as f64;
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let magnitude = (self.x * self.x + self.y * self.y) as f64;
         let magnitude = magnitude.sqrt();
 
         // Respect the formatting flags by using the helper method
@@ -558,50 +558,50 @@ pub struct Arguments<'a> {
 /// to this trait. There is not an explicit way of selecting this trait to be
 /// used for formatting, it is only if no other format is specified.
 #[allow(missing_doc)]
-pub trait Show { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Show { fn fmt(&self, &mut Formatter) -> Result; }
 
 /// Format trait for the `b` character
 #[allow(missing_doc)]
-pub trait Bool { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Bool { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `c` character
 #[allow(missing_doc)]
-pub trait Char { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Char { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `i` and `d` characters
 #[allow(missing_doc)]
-pub trait Signed { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Signed { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `u` character
 #[allow(missing_doc)]
-pub trait Unsigned { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Unsigned { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `o` character
 #[allow(missing_doc)]
-pub trait Octal { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Octal { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `b` character
 #[allow(missing_doc)]
-pub trait Binary { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Binary { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `x` character
 #[allow(missing_doc)]
-pub trait LowerHex { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait LowerHex { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `X` character
 #[allow(missing_doc)]
-pub trait UpperHex { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait UpperHex { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `s` character
 #[allow(missing_doc)]
-pub trait String { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait String { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `?` character
 #[allow(missing_doc)]
-pub trait Poly { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Poly { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `p` character
 #[allow(missing_doc)]
-pub trait Pointer { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Pointer { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `f` character
 #[allow(missing_doc)]
-pub trait Float { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait Float { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `e` character
 #[allow(missing_doc)]
-pub trait LowerExp { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait LowerExp { fn fmt(&self, &mut Formatter) -> Result; }
 /// Format trait for the `E` character
 #[allow(missing_doc)]
-pub trait UpperExp { fn fmt(&Self, &mut Formatter) -> Result; }
+pub trait UpperExp { fn fmt(&self, &mut Formatter) -> Result; }
 
 // FIXME #11938 - UFCS would make us able call the above methods
 // directly Show::show(x, fmt).
@@ -615,7 +615,7 @@ macro_rules! uniform_fn_call_workaround {
         $(
             #[doc(hidden)]
             pub fn $name<T: $trait_>(x: &T, fmt: &mut Formatter) -> Result {
-                $trait_::fmt(x, fmt)
+                x.fmt(fmt)
             }
             )*
     }
@@ -1042,44 +1042,44 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
 /// (such as for select), then it invokes this method.
 #[doc(hidden)] #[inline]
 pub fn argumentstr<'a>(s: &'a &str) -> Argument<'a> {
-    argument(String::fmt, s)
+    argument(secret_string, s)
 }
 
 /// When the compiler determines that the type of an argument *must* be a uint
 /// (such as for plural), then it invokes this method.
 #[doc(hidden)] #[inline]
 pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
-    argument(Unsigned::fmt, s)
+    argument(secret_unsigned, s)
 }
 
 // Implementations of the core formatting traits
 
 impl Bool for bool {
-    fn fmt(b: &bool, f: &mut Formatter) -> Result {
-        String::fmt(&(if *b {"true"} else {"false"}), f)
+    fn fmt(&self, f: &mut Formatter) -> Result {
+        secret_string(&(if *self {"true"} else {"false"}), f)
     }
 }
 
 impl<'a, T: str::Str> String for T {
-    fn fmt(s: &T, f: &mut Formatter) -> Result {
-        f.pad(s.as_slice())
+    fn fmt(&self, f: &mut Formatter) -> Result {
+        f.pad(self.as_slice())
     }
 }
 
 impl Char for char {
-    fn fmt(c: &char, f: &mut Formatter) -> Result {
+    fn fmt(&self, f: &mut Formatter) -> Result {
         let mut utf8 = [0u8, ..4];
-        let amt = c.encode_utf8(utf8);
+        let amt = self.encode_utf8(utf8);
         let s: &str = unsafe { cast::transmute(utf8.slice_to(amt)) };
-        String::fmt(&s, f)
+        secret_string(&s, f)
     }
 }
 
 macro_rules! int_base(($ty:ident, $into:ident, $base:expr,
                        $name:ident, $prefix:expr) => {
     impl $name for $ty {
-        fn fmt(c: &$ty, f: &mut Formatter) -> Result {
-            ::$into::to_str_bytes(*c as $into, $base, |buf| {
+        fn fmt(&self, f: &mut Formatter) -> Result {
+            ::$into::to_str_bytes(*self as $into, $base, |buf| {
                 f.pad_integral(buf, $prefix, true)
             })
         }
@@ -1087,8 +1087,8 @@ macro_rules! int_base(($ty:ident, $into:ident, $base:expr,
 })
 macro_rules! upper_hex(($ty:ident, $into:ident) => {
     impl UpperHex for $ty {
-        fn fmt(c: &$ty, f: &mut Formatter) -> Result {
-            ::$into::to_str_bytes(*c as $into, 16, |buf| {
+        fn fmt(&self, f: &mut Formatter) -> Result {
+            ::$into::to_str_bytes(*self as $into, 16, |buf| {
                 upperhex(buf, f)
             })
         }
@@ -1112,9 +1112,9 @@ macro_rules! integer(($signed:ident, $unsigned:ident) => {
     // Signed is special because it actuall emits the negative sign,
     // nothing else should do that, however.
     impl Signed for $signed {
-        fn fmt(c: &$signed, f: &mut Formatter) -> Result {
-            ::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
-                f.pad_integral(buf, "", *c >= 0)
+        fn fmt(&self, f: &mut Formatter) -> Result {
+            ::$unsigned::to_str_bytes(self.abs() as $unsigned, 10, |buf| {
+                f.pad_integral(buf, "", *self >= 0)
             })
         }
     }
@@ -1138,35 +1138,35 @@ integer!(i64, u64)
 
 macro_rules! floating(($ty:ident) => {
     impl Float for $ty {
-        fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
+        fn fmt(&self, fmt: &mut Formatter) -> Result {
             // FIXME: this shouldn't perform an allocation
             let s = match fmt.precision {
-                Some(i) => ::$ty::to_str_exact(f.abs(), i),
-                None => ::$ty::to_str_digits(f.abs(), 6)
+                Some(i) => ::$ty::to_str_exact(self.abs(), i),
+                None => ::$ty::to_str_digits(self.abs(), 6)
             };
-            fmt.pad_integral(s.as_bytes(), "", *f >= 0.0)
+            fmt.pad_integral(s.as_bytes(), "", *self >= 0.0)
         }
     }
 
     impl LowerExp for $ty {
-        fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
+        fn fmt(&self, fmt: &mut Formatter) -> Result {
             // FIXME: this shouldn't perform an allocation
             let s = match fmt.precision {
-                Some(i) => ::$ty::to_str_exp_exact(f.abs(), i, false),
-                None => ::$ty::to_str_exp_digits(f.abs(), 6, false)
+                Some(i) => ::$ty::to_str_exp_exact(self.abs(), i, false),
+                None => ::$ty::to_str_exp_digits(self.abs(), 6, false)
             };
-            fmt.pad_integral(s.as_bytes(), "", *f >= 0.0)
+            fmt.pad_integral(s.as_bytes(), "", *self >= 0.0)
         }
     }
 
     impl UpperExp for $ty {
-        fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
+        fn fmt(&self, fmt: &mut Formatter) -> Result {
             // FIXME: this shouldn't perform an allocation
             let s = match fmt.precision {
-                Some(i) => ::$ty::to_str_exp_exact(f.abs(), i, true),
-                None => ::$ty::to_str_exp_digits(f.abs(), 6, true)
+                Some(i) => ::$ty::to_str_exp_exact(self.abs(), i, true),
+                None => ::$ty::to_str_exp_digits(self.abs(), 6, true)
             };
-            fmt.pad_integral(s.as_bytes(), "", *f >= 0.0)
+            fmt.pad_integral(s.as_bytes(), "", *self >= 0.0)
         }
     }
 })
@@ -1174,16 +1174,16 @@ floating!(f32)
 floating!(f64)
 
 impl<T> Poly for T {
-    fn fmt(t: &T, f: &mut Formatter) -> Result {
+    fn fmt(&self, f: &mut Formatter) -> Result {
         match (f.width, f.precision) {
             (None, None) => {
-                repr::write_repr(f.buf, t)
+                repr::write_repr(f.buf, self)
             }
 
             // If we have a specified width for formatting, then we have to make
             // this allocation of a new string
             _ => {
-                let s = repr::repr_to_str(t);
+                let s = repr::repr_to_str(self);
                 f.pad(s)
             }
         }
@@ -1191,16 +1191,16 @@ impl<T> Poly for T {
 }
 
 impl<T> Pointer for *T {
-    fn fmt(t: &*T, f: &mut Formatter) -> Result {
+    fn fmt(&self, f: &mut Formatter) -> Result {
         f.flags |= 1 << (parse::FlagAlternate as uint);
-        ::uint::to_str_bytes(*t as uint, 16, |buf| {
+        ::uint::to_str_bytes(*self as uint, 16, |buf| {
             f.pad_integral(buf, "0x", true)
         })
     }
 }
 impl<T> Pointer for *mut T {
-    fn fmt(t: &*mut T, f: &mut Formatter) -> Result {
-        Pointer::fmt(&(*t as *T), f)
+    fn fmt(&self, f: &mut Formatter) -> Result {
+        secret_pointer(&(*self as *T), f)
     }
 }
 
@@ -1208,33 +1208,33 @@ impl<T> Pointer for *mut T {
 
 macro_rules! delegate(($ty:ty to $other:ident) => {
     impl<'a> Show for $ty {
-        fn fmt(me: &$ty, f: &mut Formatter) -> Result {
-            $other::fmt(me, f)
+        fn fmt(&self, f: &mut Formatter) -> Result {
+            (concat_idents!(secret_, $other)(self, f))
         }
     }
 })
-delegate!(int to Signed)
-delegate!( i8 to Signed)
-delegate!(i16 to Signed)
-delegate!(i32 to Signed)
-delegate!(i64 to Signed)
-delegate!(uint to Unsigned)
-delegate!(  u8 to Unsigned)
-delegate!( u16 to Unsigned)
-delegate!( u32 to Unsigned)
-delegate!( u64 to Unsigned)
-delegate!(~str to String)
-delegate!(&'a str to String)
-delegate!(bool to Bool)
-delegate!(char to Char)
-delegate!(f32 to Float)
-delegate!(f64 to Float)
+delegate!(int to signed)
+delegate!( i8 to signed)
+delegate!(i16 to signed)
+delegate!(i32 to signed)
+delegate!(i64 to signed)
+delegate!(uint to unsigned)
+delegate!(  u8 to unsigned)
+delegate!( u16 to unsigned)
+delegate!( u32 to unsigned)
+delegate!( u64 to unsigned)
+delegate!(~str to string)
+delegate!(&'a str to string)
+delegate!(bool to bool)
+delegate!(char to char)
+delegate!(f32 to float)
+delegate!(f64 to float)
 
 impl<T> Show for *T {
-    fn fmt(me: &*T, f: &mut Formatter) -> Result { Pointer::fmt(me, f) }
+    fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
 }
 impl<T> Show for *mut T {
-    fn fmt(me: &*mut T, f: &mut Formatter) -> Result { Pointer::fmt(me, f) }
+    fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
 }
 
 // If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 7690c88478f..4d28143c75a 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -364,9 +364,9 @@ pub struct IoError {
 }
 
 impl fmt::Show for IoError {
-    fn fmt(err: &IoError, fmt: &mut fmt::Formatter) -> fmt::Result {
-        if_ok!(fmt.buf.write_str(err.desc));
-        match err.detail {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        if_ok!(fmt.buf.write_str(self.desc));
+        match self.detail {
             Some(ref s) => write!(fmt.buf, " ({})", *s),
             None => Ok(())
         }
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs
index ccf3d4582de..b515cd9d31c 100644
--- a/src/libstd/io/process.rs
+++ b/src/libstd/io/process.rs
@@ -93,8 +93,8 @@ pub enum ProcessExit {
 
 impl fmt::Show for ProcessExit {
     /// Format a ProcessExit enum, to nicely present the information.
-    fn fmt(obj: &ProcessExit, f: &mut fmt::Formatter) -> fmt::Result {
-        match *obj {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
             ExitStatus(code) =>  write!(f.buf, "exit code: {}", code),
             ExitSignal(code) =>  write!(f.buf, "signal: {}", code),
         }
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index 7bb29fdfacf..5d986a73ca1 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -382,8 +382,8 @@ impl<T: Default> Option<T> {
 
 impl<T: fmt::Show> fmt::Show for Option<T> {
     #[inline]
-    fn fmt(s: &Option<T>, f: &mut fmt::Formatter) -> fmt::Result {
-        match *s {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
             Some(ref t) => write!(f.buf, "Some({})", *t),
             None        => write!(f.buf, "None")
         }
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index fb67f82d612..78cae296457 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -942,8 +942,8 @@ pub enum MapError {
 }
 
 impl fmt::Show for MapError {
-    fn fmt(val: &MapError, out: &mut fmt::Formatter) -> fmt::Result {
-        let str = match *val {
+    fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
+        let str = match *self {
             ErrFdNotAvail => "fd not available for reading or writing",
             ErrInvalidFd => "Invalid fd",
             ErrUnaligned => {
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs
index 3af42db194e..18f28994cba 100644
--- a/src/libstd/path/mod.rs
+++ b/src/libstd/path/mod.rs
@@ -494,8 +494,8 @@ pub struct Display<'a, P> {
 }
 
 impl<'a, P: GenericPath> fmt::Show for Display<'a, P> {
-    fn fmt(d: &Display<P>, f: &mut fmt::Formatter) -> fmt::Result {
-        d.with_str(|s| f.pad(s))
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.with_str(|s| f.pad(s))
     }
 }
 
diff --git a/src/libstd/result.rs b/src/libstd/result.rs
index 846bba7533f..39e8b6ad6c1 100644
--- a/src/libstd/result.rs
+++ b/src/libstd/result.rs
@@ -208,8 +208,8 @@ impl<T, E> Result<T, E> {
 
 impl<T: fmt::Show, E: fmt::Show> fmt::Show for Result<T, E> {
     #[inline]
-    fn fmt(s: &Result<T, E>, f: &mut fmt::Formatter) -> fmt::Result {
-        match *s {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
             Ok(ref t) => write!(f.buf, "Ok({})", *t),
             Err(ref e) => write!(f.buf, "Err({})", *e)
         }