]> git.lizzy.rs Git - rust.git/commitdiff
std::fmt: convert the formatting traits to a proper self.
authorHuon Wilson <dbau.pp+github@gmail.com>
Wed, 5 Feb 2014 12:55:13 +0000 (23:55 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Sat, 8 Feb 2014 02:53:21 +0000 (13:53 +1100)
Poly and String have polymorphic `impl`s and so require different method
names.

15 files changed:
src/librustdoc/html/escape.rs
src/librustdoc/html/format.rs
src/librustdoc/html/markdown.rs
src/librustdoc/html/render.rs
src/libsemver/lib.rs
src/libstd/fmt/mod.rs
src/libstd/io/mod.rs
src/libstd/io/process.rs
src/libstd/option.rs
src/libstd/os.rs
src/libstd/path/mod.rs
src/libstd/result.rs
src/libsyntax/parse/token.rs
src/test/run-pass/ifmt.rs
src/test/run-pass/logging-only-prints-once.rs

index 82850dffa2b14db89aa6a487f1c53a3b895871a0..153de66363bdb8fba32be01f47c76ce097faf846 100644 (file)
 pub struct Escape<'a>(&'a str);
 
 impl<'a> fmt::Show for Escape<'a> {
-    fn fmt(s: &Escape<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         // Because the internet is always right, turns out there's not that many
         // characters to escape: http://stackoverflow.com/questions/7381974
-        let Escape(s) = *s;
+        let Escape(s) = *self;
         let pile_o_bits = s.as_slice();
         let mut last = 0;
         for (i, ch) in s.bytes().enumerate() {
index a1a6a173ede981a81add2faddbbe29dc8caf37f8..024d010f0b927c9195f1c172e64087be9a7d3b9b 100644 (file)
@@ -48,23 +48,23 @@ pub fn get(&self) -> ast::Purity {
 }
 
 impl fmt::Show for clean::Generics {
-    fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
-        if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) }
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if self.lifetimes.len() == 0 && self.type_params.len() == 0 { return Ok(()) }
         if_ok!(f.buf.write("&lt;".as_bytes()));
 
-        for (i, life) in g.lifetimes.iter().enumerate() {
+        for (i, life) in self.lifetimes.iter().enumerate() {
             if i > 0 {
                 if_ok!(f.buf.write(", ".as_bytes()));
             }
             if_ok!(write!(f.buf, "{}", *life));
         }
 
-        if g.type_params.len() > 0 {
-            if g.lifetimes.len() > 0 {
+        if self.type_params.len() > 0 {
+            if self.lifetimes.len() > 0 {
                 if_ok!(f.buf.write(", ".as_bytes()));
             }
 
-            for (i, tp) in g.type_params.iter().enumerate() {
+            for (i, tp) in self.type_params.iter().enumerate() {
                 if i > 0 {
                     if_ok!(f.buf.write(", ".as_bytes()))
                 }
@@ -87,16 +87,16 @@ fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for clean::Lifetime {
-    fn fmt(l: &clean::Lifetime, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         if_ok!(f.buf.write("'".as_bytes()));
-        if_ok!(f.buf.write(l.get_ref().as_bytes()));
+        if_ok!(f.buf.write(self.get_ref().as_bytes()));
         Ok(())
     }
 }
 
 impl fmt::Show for clean::TyParamBound {
-    fn fmt(bound: &clean::TyParamBound, f: &mut fmt::Formatter) -> fmt::Result {
-        match *bound {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
             clean::RegionBound => {
                 f.buf.write("'static".as_bytes())
             }
@@ -108,11 +108,11 @@ fn fmt(bound: &clean::TyParamBound, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for clean::Path {
-    fn fmt(path: &clean::Path, f: &mut fmt::Formatter) -> fmt::Result {
-        if path.global {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if self.global {
             if_ok!(f.buf.write("::".as_bytes()))
         }
-        for (i, seg) in path.segments.iter().enumerate() {
+        for (i, seg) in self.segments.iter().enumerate() {
             if i > 0 {
                 if_ok!(f.buf.write("::".as_bytes()))
             }
@@ -297,8 +297,8 @@ fn typarams(w: &mut io::Writer,
 }
 
 impl fmt::Show for clean::Type {
-    fn fmt(g: &clean::Type, f: &mut fmt::Formatter) -> fmt::Result {
-        match *g {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
             clean::TyParamBinder(id) | clean::Generic(id) => {
                 local_data::get(cache_key, |cache| {
                     let m = cache.unwrap().get();
@@ -405,18 +405,18 @@ fn fmt(g: &clean::Type, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for clean::FnDecl {
-    fn fmt(d: &clean::FnDecl, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f.buf, "({args}){arrow, select, yes{ -&gt; {ret}} other{}}",
-               args = d.inputs,
-               arrow = match d.output { clean::Unit => "no", _ => "yes" },
-               ret = d.output)
+               args = self.inputs,
+               arrow = match self.output { clean::Unit => "no", _ => "yes" },
+               ret = self.output)
     }
 }
 
 impl fmt::Show for ~[clean::Argument] {
-    fn fmt(inputs: &~[clean::Argument], f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let mut args = ~"";
-        for (i, input) in inputs.iter().enumerate() {
+        for (i, input) in self.iter().enumerate() {
             if i > 0 { args.push_str(", "); }
             if input.name.len() > 0 {
                 args.push_str(format!("{}: ", input.name));
@@ -428,8 +428,8 @@ fn fmt(inputs: &~[clean::Argument], f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl<'a> fmt::Show for Method<'a> {
-    fn fmt(m: &Method<'a>, f: &mut fmt::Formatter) -> fmt::Result {
-        let Method(selfty, d) = *m;
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let Method(selfty, d) = *self;
         let mut args = ~"";
         match *selfty {
             clean::SelfStatic => {},
@@ -463,8 +463,8 @@ fn fmt(m: &Method<'a>, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for VisSpace {
-    fn fmt(v: &VisSpace, f: &mut fmt::Formatter) -> fmt::Result {
-        match v.get() {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self.get() {
             Some(ast::Public) => write!(f.buf, "pub "),
             Some(ast::Private) => write!(f.buf, "priv "),
             Some(ast::Inherited) | None => Ok(())
@@ -473,8 +473,8 @@ fn fmt(v: &VisSpace, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for PuritySpace {
-    fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) -> fmt::Result {
-        match p.get() {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self.get() {
             ast::UnsafeFn => write!(f.buf, "unsafe "),
             ast::ExternFn => write!(f.buf, "extern "),
             ast::ImpureFn => Ok(())
@@ -483,8 +483,8 @@ fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for clean::ViewPath {
-    fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) -> fmt::Result {
-        match *v {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
             clean::SimpleImport(ref name, ref src) => {
                 if *name == src.path.segments.last().unwrap().name {
                     write!(f.buf, "use {};", *src)
@@ -510,14 +510,14 @@ fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for clean::ImportSource {
-    fn fmt(v: &clean::ImportSource, f: &mut fmt::Formatter) -> fmt::Result {
-        match v.did {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self.did {
             // FIXME: shouldn't be restricted to just local imports
             Some(did) if ast_util::is_local(did) => {
-                resolved_path(f.buf, did.node, &v.path, true)
+                resolved_path(f.buf, did.node, &self.path, true)
             }
             _ => {
-                for (i, seg) in v.path.segments.iter().enumerate() {
+                for (i, seg) in self.path.segments.iter().enumerate() {
                     if i > 0 {
                         if_ok!(write!(f.buf, "::"))
                     }
@@ -530,21 +530,21 @@ fn fmt(v: &clean::ImportSource, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl fmt::Show for clean::ViewListIdent {
-    fn fmt(v: &clean::ViewListIdent, f: &mut fmt::Formatter) -> fmt::Result {
-        match v.source {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self.source {
             // FIXME: shouldn't be limited to just local imports
             Some(did) if ast_util::is_local(did) => {
                 let path = clean::Path {
                     global: false,
                     segments: ~[clean::PathSegment {
-                        name: v.name.clone(),
+                        name: self.name.clone(),
                         lifetimes: ~[],
                         types: ~[],
                     }]
                 };
                 resolved_path(f.buf, did.node, &path, false)
             }
-            _ => write!(f.buf, "{}", v.name),
+            _ => write!(f.buf, "{}", self.name),
         }
     }
 }
index c2203a352c53f5202fcd8f5b053c800437f0acac..63748203a1ab102ff1cece5376f4846a1ae4cada 100644 (file)
@@ -211,8 +211,8 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
 }
 
 impl<'a> fmt::Show for Markdown<'a> {
-    fn fmt(md: &Markdown<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
-        let Markdown(md) = *md;
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        let Markdown(md) = *self;
         // This is actually common enough to special-case
         if md.len() == 0 { return Ok(()) }
         render(fmt.buf, md.as_slice())
index cf80628da7752afaa4eb17e620b8de2d36494b45..5bd970834a64d59d0eada046a83847525334d5e1 100644 (file)
@@ -801,8 +801,8 @@ fn ismodule(&self) -> bool {
 }
 
 impl<'a> fmt::Show for Item<'a> {
-    fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
-        match attr::find_stability(it.item.attrs.iter()) {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        match attr::find_stability(self.item.attrs.iter()) {
             Some(ref stability) => {
                 if_ok!(write!(fmt.buf,
                        "<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
@@ -815,29 +815,29 @@ fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
             None => {}
         }
 
-        if it.cx.include_sources {
+        if self.cx.include_sources {
             let mut path = ~[];
-            clean_srcpath(it.item.source.filename.as_bytes(), |component| {
+            clean_srcpath(self.item.source.filename.as_bytes(), |component| {
                 path.push(component.to_owned());
             });
-            let href = if it.item.source.loline == it.item.source.hiline {
-                format!("{}", it.item.source.loline)
+            let href = if self.item.source.loline == self.item.source.hiline {
+                format!("{}", self.item.source.loline)
             } else {
-                format!("{}-{}", it.item.source.loline, it.item.source.hiline)
+                format!("{}-{}", self.item.source.loline, self.item.source.hiline)
             };
             if_ok!(write!(fmt.buf,
                           "<a class='source'
                               href='{root}src/{crate}/{path}.html\\#{href}'>\
                               [src]</a>",
-                          root = it.cx.root_path,
-                          crate = it.cx.layout.crate,
+                          root = self.cx.root_path,
+                          crate = self.cx.layout.crate,
                           path = path.connect("/"),
                           href = href));
         }
 
         // Write the breadcrumb trail header for the top
         if_ok!(write!(fmt.buf, "<h1 class='fqn'>"));
-        match it.item.inner {
+        match self.item.inner {
             clean::ModuleItem(..) => if_ok!(write!(fmt.buf, "Module ")),
             clean::FunctionItem(..) => if_ok!(write!(fmt.buf, "Function ")),
             clean::TraitItem(..) => if_ok!(write!(fmt.buf, "Trait ")),
@@ -845,8 +845,8 @@ fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
             clean::EnumItem(..) => if_ok!(write!(fmt.buf, "Enum ")),
             _ => {}
         }
-        let cur = it.cx.current.as_slice();
-        let amt = if it.ismodule() { cur.len() - 1 } else { cur.len() };
+        let cur = self.cx.current.as_slice();
+        let amt = if self.ismodule() { cur.len() - 1 } else { cur.len() };
         for (i, component) in cur.iter().enumerate().take(amt) {
             let mut trail = ~"";
             for _ in range(0, cur.len() - i - 1) {
@@ -856,17 +856,17 @@ fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
                           trail, component.as_slice()));
         }
         if_ok!(write!(fmt.buf, "<a class='{}' href=''>{}</a></h1>",
-                      shortty(it.item), it.item.name.get_ref().as_slice()));
+                      shortty(self.item), self.item.name.get_ref().as_slice()));
 
-        match it.item.inner {
-            clean::ModuleItem(ref m) => item_module(fmt.buf, it.cx,
-                                                    it.item, m.items),
+        match self.item.inner {
+            clean::ModuleItem(ref m) => item_module(fmt.buf, self.cx,
+                                                    self.item, m.items),
             clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
-                item_function(fmt.buf, it.item, f),
-            clean::TraitItem(ref t) => item_trait(fmt.buf, it.item, t),
-            clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
-            clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
-            clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
+                item_function(fmt.buf, self.item, f),
+            clean::TraitItem(ref t) => item_trait(fmt.buf, self.item, t),
+            clean::StructItem(ref s) => item_struct(fmt.buf, self.item, s),
+            clean::EnumItem(ref e) => item_enum(fmt.buf, self.item, e),
+            clean::TypedefItem(ref t) => item_typedef(fmt.buf, self.item, t),
             _ => Ok(())
         }
     }
@@ -992,9 +992,8 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> Ordering {
             clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
                 struct Initializer<'a>(&'a str);
                 impl<'a> fmt::Show for Initializer<'a> {
-                    fn fmt(s: &Initializer<'a>,
-                           f: &mut fmt::Formatter) -> fmt::Result {
-                        let Initializer(s) = *s;
+                    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+                        let Initializer(s) = *self;
                         if s.len() == 0 { return Ok(()); }
                         if_ok!(write!(f.buf, "<code> = </code>"));
                         let tag = if s.contains("\n") { "pre" } else { "code" };
@@ -1518,9 +1517,9 @@ fn item_typedef(w: &mut Writer, it: &clean::Item,
 }
 
 impl<'a> fmt::Show for Sidebar<'a> {
-    fn fmt(s: &Sidebar<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
-        let cx = s.cx;
-        let it = s.item;
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        let cx = self.cx;
+        let it = self.item;
         if_ok!(write!(fmt.buf, "<p class='location'>"));
         let len = cx.current.len() - if it.is_mod() {1} else {0};
         for (i, name) in cx.current.iter().take(len).enumerate() {
@@ -1588,8 +1587,8 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
 }
 
 impl<'a> fmt::Show for Source<'a> {
-    fn fmt(s: &Source<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
-        let Source(s) = *s;
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        let Source(s) = *self;
         let lines = s.lines().len();
         let mut cols = 0;
         let mut tmp = lines;
index 9c5dd656d427deb52427d3443d4154867132a58a..7d50cf551a0cea99ac52e06f50b07cf2ce525191 100644 (file)
@@ -36,6 +36,7 @@
 use std::char;
 use std::cmp;
 use std::fmt;
+use std::fmt::Show;
 use std::option::{Option, Some, None};
 use std::to_str::ToStr;
 
@@ -62,10 +63,10 @@ fn lt(&self, other: &Identifier) -> bool {
 
 impl fmt::Show for Identifier {
     #[inline]
-    fn fmt(version: &Identifier, f: &mut fmt::Formatter) -> fmt::Result {
-        match *version {
-            Numeric(ref n) => fmt::Show::fmt(n, f),
-            AlphaNumeric(ref s) => fmt::Show::fmt(s, f)
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            Numeric(ref n) => n.fmt(f),
+            AlphaNumeric(ref s) => s.fmt(f)
         }
     }
 }
@@ -97,20 +98,20 @@ pub struct Version {
 
 impl fmt::Show for Version {
     #[inline]
-    fn fmt(version: &Version, f: &mut fmt::Formatter) -> fmt::Result {
-        if_ok!(write!(f.buf, "{}.{}.{}", version.major, version.minor, version.patch))
-        if !version.pre.is_empty() {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if_ok!(write!(f.buf, "{}.{}.{}", self.major, self.minor, self.patch))
+        if !self.pre.is_empty() {
             if_ok!(write!(f.buf, "-"));
-            for (i, x) in version.pre.iter().enumerate() {
+            for (i, x) in self.pre.iter().enumerate() {
                 if i != 0 { if_ok!(write!(f.buf, ".")) };
-                if_ok!(fmt::Show::fmt(x, f));
+                if_ok!(x.fmt(f));
             }
         }
-        if !version.build.is_empty() {
+        if !self.build.is_empty() {
             if_ok!(write!(f.buf, "+"));
-            for (i, x) in version.build.iter().enumerate() {
+            for (i, x) in self.build.iter().enumerate() {
                 if i != 0 { if_ok!(write!(f.buf, ".")) };
-                if_ok!(fmt::Show::fmt(x, f));
+                if_ok!(x.fmt(f));
             }
         }
         Ok(())
index 40ad1fb250a86082d2e71c60406c445690a67adf..d2e9fe040f7eddebad15b223733dfc4f2694f7be 100644 (file)
 # 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 @@ fn fmt(c: &$ty, f: &mut Formatter) -> Result {
 })
 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 @@ fn fmt(c: &$signed, f: &mut Formatter) -> Result {
 
 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 @@ fn fmt(f: &$ty, fmt: &mut Formatter) -> Result {
 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 @@ fn fmt(t: &T, f: &mut Formatter) -> Result {
 }
 
 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 @@ fn fmt(t: &*mut T, f: &mut Formatter) -> Result {
 
 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,
index 7690c88478fdeac333ef453f610cf093e9952a4f..4d28143c75ab65d1e8ba6e5bd482cb615edae805 100644 (file)
@@ -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(())
         }
index ccf3d4582def4d5bf566b0e4e7a92c7b9d12bc0a..b515cd9d31c0eb5048e22a46d112b8104f531daa 100644 (file)
@@ -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),
         }
index 7bb29fdfacf65177d7fdef5b15f4e71a92366d21..5d986a73ca14d1d46326a81db98aaf32d371e233 100644 (file)
@@ -382,8 +382,8 @@ pub fn unwrap_or_default(self) -> 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")
         }
index fb67f82d612a61ffc66565ac3224fac044ac6f5e..78cae2964570c995ab965af89e55ad728a175acf 100644 (file)
@@ -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 => {
index 3af42db194e4ddcca2e498a3cfa79b8f16cb18a1..18f28994cba9697835114365f2c755d2862ded95 100644 (file)
@@ -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))
     }
 }
 
index 846bba7533fed755ceee6972b440d672dee5ff26..39e8b6ad6c1d2608f0634bf6aa0dc217d13ab5cc 100644 (file)
@@ -208,8 +208,8 @@ pub fn unwrap_err(self) -> 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)
         }
index 090774ec76ff290f2c1c9225067978271a19480d..d32411b4f050ae1f10aa28000c99706db59c4f32 100644 (file)
@@ -588,8 +588,8 @@ fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
 }
 
 impl fmt::Show for InternedString {
-    fn fmt(obj: &InternedString, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f.buf, "{}", obj.string.as_slice())
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f.buf, "{}", self.string.as_slice())
     }
 }
 
index b66446b0cfe438aa75beed8fc3d5a25ab1002edd..4a82007f0600462a846913179ec1e72b634d5ab8 100644 (file)
 struct B;
 
 impl fmt::Signed for A {
-    fn fmt(_: &A, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.buf.write("aloha".as_bytes())
     }
 }
 impl fmt::Signed for B {
-    fn fmt(_: &B, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.buf.write("adios".as_bytes())
     }
 }
index dccdc8ae3ba21652fca1950a6927eeca17f3cb71..8c6a366220cec522ee66a91e991ce45f0591d356 100644 (file)
@@ -17,8 +17,8 @@
 struct Foo(Cell<int>);
 
 impl fmt::Show for Foo {
-    fn fmt(f: &Foo, _fmt: &mut fmt::Formatter) -> fmt::Result {
-        let Foo(ref f) = *f;
+    fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result {
+        let Foo(ref f) = *self;
         assert!(f.get() == 0);
         f.set(1);
         Ok(())