From 44440e5c18a1dbcc9685866ffffe00c508929079 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 20 Dec 2014 00:09:35 -0800 Subject: core: split into fmt::Show and fmt::String fmt::Show is for debugging, and can and should be implemented for all public types. This trait is used with `{:?}` syntax. There still exists #[derive(Show)]. fmt::String is for types that faithfully be represented as a String. Because of this, there is no way to derive fmt::String, all implementations must be purposeful. It is used by the default format syntax, `{}`. This will break most instances of `{}`, since that now requires the type to impl fmt::String. In most cases, replacing `{}` with `{:?}` is the correct fix. Types that were being printed specifically for users should receive a fmt::String implementation to fix this. Part of #20013 [breaking-change] --- src/librustdoc/html/render.rs | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/librustdoc/html/render.rs') diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ddb14d6944b..5ec970c5a50 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1051,7 +1051,7 @@ impl Context { F: FnOnce(&mut Context) -> T, { if s.len() == 0 { - panic!("Unexpected empty destination: {}", self.current); + panic!("Unexpected empty destination: {:?}", self.current); } let prev = self.dst.clone(); self.dst.push(s.as_slice()); @@ -1351,8 +1351,15 @@ impl<'a> Item<'a> { } - +//NOTE(stage0): remove impl after snapshot +#[cfg(stage0)] impl<'a> fmt::Show for Item<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl<'a> fmt::String for Item<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { // Write the breadcrumb trail header for the top try!(write!(fmt, "\n

")); @@ -1542,7 +1549,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2)); - debug!("{}", indices); + debug!("{:?}", indices); let mut curty = None; for &idx in indices.iter() { let myitem = &items[idx]; @@ -1626,7 +1633,16 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, } struct Initializer<'a>(&'a str); + +//NOTE(stage0): remove impl after snapshot +#[cfg(stage0)] impl<'a> fmt::Show for Initializer<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl<'a> fmt::String for Initializer<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let Initializer(s) = *self; if s.len() == 0 { return Ok(()); } @@ -2127,7 +2143,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result { try!(assoc_type(w, item, typaram)); try!(write!(w, "

\n")); } - _ => panic!("can't make docs for trait item with name {}", item.name) + _ => panic!("can't make docs for trait item with name {:?}", item.name) } match item.doc_value() { Some(s) if dox => { @@ -2188,7 +2204,15 @@ fn item_typedef(w: &mut fmt::Formatter, it: &clean::Item, document(w, it) } +//NOTE(stage0): remove impl after snapshot +#[cfg(stage0)] impl<'a> fmt::Show for Sidebar<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl<'a> fmt::String for Sidebar<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let cx = self.cx; let it = self.item; @@ -2243,7 +2267,15 @@ impl<'a> fmt::Show for Sidebar<'a> { } } +//NOTE(stage0): remove impl after snapshot +#[cfg(stage0)] impl<'a> fmt::Show for Source<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl<'a> fmt::String for Source<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let Source(s) = *self; let lines = s.lines().count(); -- cgit 1.4.1-3-g733a5