Skip to content

Commit 003ce50

Browse files
committed
std: rename fmt::Default to Show.
This is a better name with which to have a #[deriving] mode. Decision in: https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-01-28
1 parent 2bcd951 commit 003ce50

File tree

14 files changed

+75
-56
lines changed

14 files changed

+75
-56
lines changed

src/librustdoc/html/escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::fmt;
1919
/// string when passed to a format string.
2020
pub struct Escape<'a>(&'a str);
2121

22-
impl<'a> fmt::Default for Escape<'a> {
22+
impl<'a> fmt::Show for Escape<'a> {
2323
fn fmt(s: &Escape<'a>, fmt: &mut fmt::Formatter) {
2424
// Because the internet is always right, turns out there's not that many
2525
// characters to escape: http://stackoverflow.com/questions/7381974

src/librustdoc/html/format.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! HTML formatting module
1212
//!
13-
//! This module contains a large number of `fmt::Default` implementations for
13+
//! This module contains a large number of `fmt::Show` implementations for
1414
//! various types in `rustdoc::clean`. These implementations all currently
1515
//! assume that HTML output is desired, although it may be possible to redesign
1616
//! them in the future to instead emit any format desired.
@@ -47,7 +47,7 @@ impl PuritySpace {
4747
}
4848
}
4949

50-
impl fmt::Default for clean::Generics {
50+
impl fmt::Show for clean::Generics {
5151
fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) {
5252
if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return }
5353
f.buf.write("&lt;".as_bytes());
@@ -77,14 +77,14 @@ impl fmt::Default for clean::Generics {
7777
}
7878
}
7979

80-
impl fmt::Default for clean::Lifetime {
80+
impl fmt::Show for clean::Lifetime {
8181
fn fmt(l: &clean::Lifetime, f: &mut fmt::Formatter) {
8282
f.buf.write("'".as_bytes());
8383
f.buf.write(l.get_ref().as_bytes());
8484
}
8585
}
8686

87-
impl fmt::Default for clean::TyParamBound {
87+
impl fmt::Show for clean::TyParamBound {
8888
fn fmt(bound: &clean::TyParamBound, f: &mut fmt::Formatter) {
8989
match *bound {
9090
clean::RegionBound => {
@@ -97,7 +97,7 @@ impl fmt::Default for clean::TyParamBound {
9797
}
9898
}
9999

100-
impl fmt::Default for clean::Path {
100+
impl fmt::Show for clean::Path {
101101
fn fmt(path: &clean::Path, f: &mut fmt::Formatter) {
102102
if path.global { f.buf.write("::".as_bytes()) }
103103
for (i, seg) in path.segments.iter().enumerate() {
@@ -269,7 +269,7 @@ fn typarams(w: &mut io::Writer, typarams: &Option<~[clean::TyParamBound]>) {
269269
}
270270
}
271271

272-
impl fmt::Default for clean::Type {
272+
impl fmt::Show for clean::Type {
273273
fn fmt(g: &clean::Type, f: &mut fmt::Formatter) {
274274
match *g {
275275
clean::TyParamBinder(id) | clean::Generic(id) => {
@@ -374,7 +374,7 @@ impl fmt::Default for clean::Type {
374374
}
375375
}
376376

377-
impl fmt::Default for clean::FnDecl {
377+
impl fmt::Show for clean::FnDecl {
378378
fn fmt(d: &clean::FnDecl, f: &mut fmt::Formatter) {
379379
write!(f.buf, "({args}){arrow, select, yes{ -&gt; {ret}} other{}}",
380380
args = d.inputs,
@@ -383,7 +383,7 @@ impl fmt::Default for clean::FnDecl {
383383
}
384384
}
385385

386-
impl fmt::Default for ~[clean::Argument] {
386+
impl fmt::Show for ~[clean::Argument] {
387387
fn fmt(inputs: &~[clean::Argument], f: &mut fmt::Formatter) {
388388
let mut args = ~"";
389389
for (i, input) in inputs.iter().enumerate() {
@@ -397,7 +397,7 @@ impl fmt::Default for ~[clean::Argument] {
397397
}
398398
}
399399

400-
impl<'a> fmt::Default for Method<'a> {
400+
impl<'a> fmt::Show for Method<'a> {
401401
fn fmt(m: &Method<'a>, f: &mut fmt::Formatter) {
402402
let Method(selfty, d) = *m;
403403
let mut args = ~"";
@@ -433,7 +433,7 @@ impl<'a> fmt::Default for Method<'a> {
433433
}
434434
}
435435

436-
impl fmt::Default for VisSpace {
436+
impl fmt::Show for VisSpace {
437437
fn fmt(v: &VisSpace, f: &mut fmt::Formatter) {
438438
match v.get() {
439439
Some(ast::Public) => { write!(f.buf, "pub "); }
@@ -443,7 +443,7 @@ impl fmt::Default for VisSpace {
443443
}
444444
}
445445

446-
impl fmt::Default for PuritySpace {
446+
impl fmt::Show for PuritySpace {
447447
fn fmt(p: &PuritySpace, f: &mut fmt::Formatter) {
448448
match p.get() {
449449
ast::UnsafeFn => write!(f.buf, "unsafe "),
@@ -453,7 +453,7 @@ impl fmt::Default for PuritySpace {
453453
}
454454
}
455455

456-
impl fmt::Default for clean::ViewPath {
456+
impl fmt::Show for clean::ViewPath {
457457
fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) {
458458
match *v {
459459
clean::SimpleImport(ref name, ref src) => {
@@ -478,7 +478,7 @@ impl fmt::Default for clean::ViewPath {
478478
}
479479
}
480480

481-
impl fmt::Default for clean::ImportSource {
481+
impl fmt::Show for clean::ImportSource {
482482
fn fmt(v: &clean::ImportSource, f: &mut fmt::Formatter) {
483483
match v.did {
484484
// FIXME: shouldn't be restricted to just local imports
@@ -495,7 +495,7 @@ impl fmt::Default for clean::ImportSource {
495495
}
496496
}
497497

498-
impl fmt::Default for clean::ViewListIdent {
498+
impl fmt::Show for clean::ViewListIdent {
499499
fn fmt(v: &clean::ViewListIdent, f: &mut fmt::Formatter) {
500500
match v.source {
501501
// FIXME: shouldn't be limited to just local imports

src/librustdoc/html/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Page<'a> {
2424
root_path: &'a str,
2525
}
2626

27-
pub fn render<T: fmt::Default, S: fmt::Default>(
27+
pub fn render<T: fmt::Show, S: fmt::Show>(
2828
dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
2929
{
3030
write!(dst,

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! (bundled into the rust runtime). This module self-contains the C bindings
1515
//! and necessary legwork to render markdown, and exposes all of the
1616
//! functionality through a unit-struct, `Markdown`, which has an implementation
17-
//! of `fmt::Default`. Example usage:
17+
//! of `fmt::Show`. Example usage:
1818
//!
1919
//! ```rust,ignore
2020
//! use rustdoc::html::markdown::Markdown;
@@ -32,7 +32,7 @@ use std::str;
3232
use std::unstable::intrinsics;
3333
use std::vec;
3434

35-
/// A unit struct which has the `fmt::Default` trait implemented. When
35+
/// A unit struct which has the `fmt::Show` trait implemented. When
3636
/// formatted, this struct will emit the HTML corresponding to the rendered
3737
/// version of the contained markdown string.
3838
pub struct Markdown<'a>(&'a str);
@@ -209,7 +209,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
209209
}
210210
}
211211

212-
impl<'a> fmt::Default for Markdown<'a> {
212+
impl<'a> fmt::Show for Markdown<'a> {
213213
fn fmt(md: &Markdown<'a>, fmt: &mut fmt::Formatter) {
214214
let Markdown(md) = *md;
215215
// This is actually common enough to special-case

src/librustdoc/html/render.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<'a> Item<'a> {
801801
}
802802
}
803803

804-
impl<'a> fmt::Default for Item<'a> {
804+
impl<'a> fmt::Show for Item<'a> {
805805
fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) {
806806
match attr::find_stability(it.item.attrs.iter()) {
807807
Some(ref stability) => {
@@ -990,7 +990,7 @@ fn item_module(w: &mut Writer, cx: &Context,
990990
match myitem.inner {
991991
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
992992
struct Initializer<'a>(&'a str);
993-
impl<'a> fmt::Default for Initializer<'a> {
993+
impl<'a> fmt::Show for Initializer<'a> {
994994
fn fmt(s: &Initializer<'a>, f: &mut fmt::Formatter) {
995995
let Initializer(s) = *s;
996996
if s.len() == 0 { return; }
@@ -1491,7 +1491,7 @@ fn item_typedef(w: &mut Writer, it: &clean::Item, t: &clean::Typedef) {
14911491
document(w, it);
14921492
}
14931493

1494-
impl<'a> fmt::Default for Sidebar<'a> {
1494+
impl<'a> fmt::Show for Sidebar<'a> {
14951495
fn fmt(s: &Sidebar<'a>, fmt: &mut fmt::Formatter) {
14961496
let cx = s.cx;
14971497
let it = s.item;
@@ -1556,7 +1556,7 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
15561556
return map;
15571557
}
15581558

1559-
impl<'a> fmt::Default for Source<'a> {
1559+
impl<'a> fmt::Show for Source<'a> {
15601560
fn fmt(s: &Source<'a>, fmt: &mut fmt::Formatter) {
15611561
let Source(s) = *s;
15621562
let lines = s.lines().len();

src/libstd/fmt/mod.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ The current mapping of types to traits is:
149149
* `f` ⇒ `Float`
150150
* `e` ⇒ `LowerExp`
151151
* `E` ⇒ `UpperExp`
152-
* *nothing* ⇒ `Default`
152+
* *nothing* ⇒ `Show`
153153
154154
What this means is that any type of argument which implements the
155155
`std::fmt::Binary` trait can then be formatted with `{:t}`. Implementations are
156156
provided for these traits for a number of primitive types by the standard
157157
library as well. If no format is specified (as in `{}` or `{:6}`), then the
158-
format trait used is the `Default` trait. This is one of the more commonly
158+
format trait used is the `Show` trait. This is one of the more commonly
159159
implemented traits when formatting a custom type.
160160
161161
When implementing a format trait for your own time, you will have to implement a
@@ -186,7 +186,7 @@ struct Vector2D {
186186
y: int,
187187
}
188188
189-
impl fmt::Default for Vector2D {
189+
impl fmt::Show for Vector2D {
190190
fn fmt(obj: &Vector2D, f: &mut fmt::Formatter) {
191191
// The `f.buf` value is of the type `&mut io::Writer`, which is what th
192192
// write! macro is expecting. Note that this formatting ignores the
@@ -468,6 +468,7 @@ will look like `"\\{"`.
468468
469469
*/
470470

471+
#[cfg(not(stage0))]
471472
use prelude::*;
472473

473474
use cast;
@@ -479,6 +480,24 @@ use repr;
479480
use util;
480481
use vec;
481482

483+
// SNAP b6400f9 this is just because the `prelude::*` import above
484+
// includes default::Default, so the reexport doesn't work.
485+
#[cfg(stage0)]
486+
pub use Default = fmt::Show; // export required for `format!()` etc.
487+
488+
#[cfg(stage0)]
489+
use container::Container;
490+
#[cfg(stage0)]
491+
use iter::{Iterator, range};
492+
#[cfg(stage0)]
493+
use option::{Option,Some,None};
494+
#[cfg(stage0)]
495+
use vec::ImmutableVector;
496+
#[cfg(stage0)]
497+
use str::StrSlice;
498+
#[cfg(stage0)]
499+
use num::Signed;
500+
482501
pub mod parse;
483502
pub mod rt;
484503

@@ -542,7 +561,7 @@ pub struct Arguments<'a> {
542561
/// to this trait. There is not an explicit way of selecting this trait to be
543562
/// used for formatting, it is only if no other format is specified.
544563
#[allow(missing_doc)]
545-
pub trait Default { fn fmt(&Self, &mut Formatter); }
564+
pub trait Show { fn fmt(&Self, &mut Formatter); }
546565

547566
/// Format trait for the `b` character
548567
#[allow(missing_doc)]
@@ -1148,10 +1167,10 @@ impl<T> Pointer for *mut T {
11481167
fn fmt(t: &*mut T, f: &mut Formatter) { Pointer::fmt(&(*t as *T), f) }
11491168
}
11501169

1151-
// Implementation of Default for various core types
1170+
// Implementation of Show for various core types
11521171

11531172
macro_rules! delegate(($ty:ty to $other:ident) => {
1154-
impl<'a> Default for $ty {
1173+
impl<'a> Show for $ty {
11551174
fn fmt(me: &$ty, f: &mut Formatter) {
11561175
$other::fmt(me, f)
11571176
}
@@ -1174,10 +1193,10 @@ delegate!(char to Char)
11741193
delegate!(f32 to Float)
11751194
delegate!(f64 to Float)
11761195

1177-
impl<T> Default for *T {
1196+
impl<T> Show for *T {
11781197
fn fmt(me: &*T, f: &mut Formatter) { Pointer::fmt(me, f) }
11791198
}
1180-
impl<T> Default for *mut T {
1199+
impl<T> Show for *mut T {
11811200
fn fmt(me: &*mut T, f: &mut Formatter) { Pointer::fmt(me, f) }
11821201
}
11831202

src/libstd/io/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum ProcessExit {
9191
ExitSignal(int),
9292
}
9393

94-
impl fmt::Default for ProcessExit {
94+
impl fmt::Show for ProcessExit {
9595
/// Format a ProcessExit enum, to nicely present the information.
9696
fn fmt(obj: &ProcessExit, f: &mut fmt::Formatter) {
9797
match *obj {

src/libstd/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<T: Default> Option<T> {
380380
// Trait implementations
381381
/////////////////////////////////////////////////////////////////////////////
382382

383-
impl<T: fmt::Default> fmt::Default for Option<T> {
383+
impl<T: fmt::Show> fmt::Show for Option<T> {
384384
#[inline]
385385
fn fmt(s: &Option<T>, f: &mut fmt::Formatter) {
386386
match *s {

src/libstd/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ pub enum MapError {
928928
ErrMapViewOfFile(uint)
929929
}
930930

931-
impl fmt::Default for MapError {
931+
impl fmt::Show for MapError {
932932
fn fmt(val: &MapError, out: &mut fmt::Formatter) {
933933
let str = match *val {
934934
ErrFdNotAvail => "fd not available for reading or writing",

src/libstd/path/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
198198
/// Converts the Path into an owned byte vector
199199
fn into_vec(self) -> ~[u8];
200200

201-
/// Returns an object that implements `fmt::Default` for printing paths
201+
/// Returns an object that implements `Show` for printing paths
202202
///
203203
/// This will print the equivalent of `to_display_str()` when used with a {} format parameter.
204204
fn display<'a>(&'a self) -> Display<'a, Self> {
205205
Display{ path: self, filename: false }
206206
}
207207

208-
/// Returns an object that implements `fmt::Default` for printing filenames
208+
/// Returns an object that implements `Show` for printing filenames
209209
///
210210
/// This will print the equivalent of `to_filename_display_str()` when used with a {}
211211
/// format parameter. If there is no filename, nothing will be printed.
@@ -532,7 +532,7 @@ pub struct Display<'a, P> {
532532
priv filename: bool
533533
}
534534

535-
impl<'a, P: GenericPath> fmt::Default for Display<'a, P> {
535+
impl<'a, P: GenericPath> fmt::Show for Display<'a, P> {
536536
fn fmt(d: &Display<P>, f: &mut fmt::Formatter) {
537537
d.with_str(|s| f.pad(s))
538538
}

src/libstd/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<T, E> Result<T, E> {
206206
// Trait implementations
207207
/////////////////////////////////////////////////////////////////////////////
208208

209-
impl<T: fmt::Default, E: fmt::Default> fmt::Default for Result<T, E> {
209+
impl<T: fmt::Show, E: fmt::Show> fmt::Show for Result<T, E> {
210210
#[inline]
211211
fn fmt(s: &Result<T, E>, f: &mut fmt::Formatter) {
212212
match *s {

src/libsyntax/ext/format.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -704,22 +704,22 @@ impl<'a> Context<'a> {
704704

705705
let fmt_trait = match *ty {
706706
Known(ref tyname) => {
707-
match (*tyname).as_slice() {
708-
"" => "Default",
709-
"?" => "Poly",
710-
"b" => "Bool",
711-
"c" => "Char",
712-
"d" | "i" => "Signed",
713-
"e" => "LowerExp",
714-
"E" => "UpperExp",
715-
"f" => "Float",
716-
"o" => "Octal",
717-
"p" => "Pointer",
718-
"s" => "String",
719-
"t" => "Binary",
720-
"u" => "Unsigned",
721-
"x" => "LowerHex",
722-
"X" => "UpperHex",
707+
match tyname.as_slice() {
708+
"" => "secret_show",
709+
"?" => "secret_poly",
710+
"b" => "secret_bool",
711+
"c" => "secret_char",
712+
"d" | "i" => "secret_signed",
713+
"e" => "secret_lower_exp",
714+
"E" => "secret_upper_exp",
715+
"f" => "secret_float",
716+
"o" => "secret_octal",
717+
"p" => "secret_pointer",
718+
"s" => "secret_string",
719+
"t" => "secret_binary",
720+
"u" => "secret_unsigned",
721+
"x" => "secret_lower_hex",
722+
"X" => "secret_upper_hex",
723723
_ => {
724724
self.ecx.span_err(sp,
725725
format!("unknown format trait `{}`",

0 commit comments

Comments
 (0)