Skip to content

Commit a204dc5

Browse files
committed
rollup merge of #20722: alexcrichton/audit-show
Conflicts: src/libcollections/vec.rs src/libcore/fmt/mod.rs src/librustdoc/html/format.rs
2 parents a6bf767 + 9851b4f commit a204dc5

22 files changed

+75
-77
lines changed

src/liballoc/arc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,13 @@ impl<T: fmt::Show> fmt::Show for Arc<T> {
584584
}
585585
}
586586

587+
#[stable]
588+
impl<T: fmt::String> fmt::String for Arc<T> {
589+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
590+
fmt::String::fmt(&**self, f)
591+
}
592+
}
593+
587594
#[stable]
588595
impl<T: Default + Sync + Send> Default for Arc<T> {
589596
#[stable]

src/liballoc/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
157157
}
158158
}
159159

160+
#[stable]
160161
impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
161162
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
162163
fmt::String::fmt(&**self, f)

src/liballoc/rc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,13 @@ impl<T: fmt::Show> fmt::Show for Rc<T> {
622622
}
623623
}
624624

625+
#[stable]
626+
impl<T: fmt::String> fmt::String for Rc<T> {
627+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
628+
fmt::String::fmt(&**self, f)
629+
}
630+
}
631+
625632
/// A weak version of `Rc<T>`.
626633
///
627634
/// Weak references do not count when determining if the inner value should be dropped.

src/libcollections/string.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ impl fmt::Show for FromUtf8Error {
681681
}
682682
}
683683

684+
#[stable]
684685
impl fmt::String for FromUtf8Error {
685686
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
686687
fmt::String::fmt(&self.error, f)
@@ -693,6 +694,7 @@ impl fmt::Show for FromUtf16Error {
693694
}
694695
}
695696

697+
#[stable]
696698
impl fmt::String for FromUtf16Error {
697699
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
698700
fmt::String::fmt("invalid utf-16: lone surrogate found", f)
@@ -805,7 +807,7 @@ impl Default for String {
805807
}
806808
}
807809

808-
#[experimental = "waiting on fmt stabilization"]
810+
#[stable]
809811
impl fmt::String for String {
810812
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
811813
fmt::String::fmt(&**self, f)
@@ -1274,18 +1276,17 @@ mod tests {
12741276
assert_eq!(2u8.to_string(), "2");
12751277
assert_eq!(true.to_string(), "true");
12761278
assert_eq!(false.to_string(), "false");
1277-
assert_eq!(().to_string(), "()");
12781279
assert_eq!(("hi".to_string()).to_string(), "hi");
12791280
}
12801281

12811282
#[test]
12821283
fn test_vectors() {
12831284
let x: Vec<int> = vec![];
1284-
assert_eq!(x.to_string(), "[]");
1285-
assert_eq!((vec![1i]).to_string(), "[1]");
1286-
assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]");
1287-
assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() ==
1288-
"[[], [1], [1, 1]]");
1285+
assert_eq!(format!("{:?}", x), "[]");
1286+
assert_eq!(format!("{:?}", vec![1i]), "[1i]");
1287+
assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1i, 2i, 3i]");
1288+
assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) ==
1289+
"[[], [1i], [1i, 1i]]");
12891290
}
12901291

12911292
#[test]

src/libcollections/vec.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,13 +1462,6 @@ impl<T: fmt::Show> fmt::Show for Vec<T> {
14621462
}
14631463
}
14641464

1465-
#[experimental = "waiting on Show stability"]
1466-
impl<T: fmt::String> fmt::String for Vec<T> {
1467-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1468-
fmt::String::fmt(self.as_slice(), f)
1469-
}
1470-
}
1471-
14721465
impl<'a> fmt::Writer for Vec<u8> {
14731466
fn write_str(&mut self, s: &str) -> fmt::Result {
14741467
self.push_all(s.as_bytes());

src/libcore/borrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwne
238238
}
239239
}
240240

241+
#[stable]
241242
impl<'a, T, B: ?Sized> fmt::String for Cow<'a, T, B> where
242243
B: fmt::String + ToOwned<T>,
243244
T: fmt::String,

src/libcore/fmt/mod.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl<'a> Show for Arguments<'a> {
219219
}
220220
}
221221

222+
#[stable]
222223
impl<'a> String for Arguments<'a> {
223224
fn fmt(&self, fmt: &mut Formatter) -> Result {
224225
write(fmt.buf, *self)
@@ -627,6 +628,7 @@ impl Show for bool {
627628
}
628629
}
629630

631+
#[stable]
630632
impl String for bool {
631633
fn fmt(&self, f: &mut Formatter) -> Result {
632634
String::fmt(if *self { "true" } else { "false" }, f)
@@ -643,6 +645,7 @@ impl Show for str {
643645
}
644646
}
645647

648+
#[stable]
646649
impl String for str {
647650
fn fmt(&self, f: &mut Formatter) -> Result {
648651
f.pad(self)
@@ -660,6 +663,7 @@ impl Show for char {
660663
}
661664
}
662665

666+
#[stable]
663667
impl String for char {
664668
fn fmt(&self, f: &mut Formatter) -> Result {
665669
let mut utf8 = [0u8; 4];
@@ -705,6 +709,7 @@ macro_rules! floating { ($ty:ident) => {
705709
}
706710
}
707711

712+
#[stable]
708713
impl String for $ty {
709714
fn fmt(&self, fmt: &mut Formatter) -> Result {
710715
use num::Float;
@@ -776,15 +781,9 @@ floating! { f64 }
776781
impl<T> Show for *const T {
777782
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
778783
}
779-
impl<T> String for *const T {
780-
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
781-
}
782784
impl<T> Show for *mut T {
783785
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
784786
}
785-
impl<T> String for *mut T {
786-
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
787-
}
788787

789788
macro_rules! peel {
790789
($name:ident, $($other:ident,)*) => (tuple! { $($other,)* })
@@ -843,39 +842,12 @@ impl<T: Show> Show for [T] {
843842
}
844843
}
845844

846-
impl<T: String> String for [T] {
847-
fn fmt(&self, f: &mut Formatter) -> Result {
848-
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
849-
try!(write!(f, "["));
850-
}
851-
let mut is_first = true;
852-
for x in self.iter() {
853-
if is_first {
854-
is_first = false;
855-
} else {
856-
try!(write!(f, ", "));
857-
}
858-
try!(write!(f, "{}", *x))
859-
}
860-
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
861-
try!(write!(f, "]"));
862-
}
863-
Ok(())
864-
}
865-
}
866-
867845
impl Show for () {
868846
fn fmt(&self, f: &mut Formatter) -> Result {
869847
f.pad("()")
870848
}
871849
}
872850

873-
impl String for () {
874-
fn fmt(&self, f: &mut Formatter) -> Result {
875-
f.pad("()")
876-
}
877-
}
878-
879851
impl<T: Copy + Show> Show for Cell<T> {
880852
fn fmt(&self, f: &mut Formatter) -> Result {
881853
write!(f, "Cell {{ value: {:?} }}", self.get())
@@ -904,6 +876,7 @@ impl<'b, T: Show> Show for RefMut<'b, T> {
904876
}
905877
}
906878

879+
#[stable]
907880
impl String for Utf8Error {
908881
fn fmt(&self, f: &mut Formatter) -> Result {
909882
match *self {

src/libcore/option.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,18 @@
145145

146146
use self::Option::*;
147147

148+
use clone::Clone;
148149
use cmp::{Eq, Ord};
149150
use default::Default;
150-
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
151+
use fmt;
151152
use iter::{ExactSizeIterator};
153+
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
152154
use mem;
153-
use result::Result;
155+
use ops::{Deref, FnOnce};
154156
use result::Result::{Ok, Err};
155-
use slice;
157+
use result::Result;
156158
use slice::AsSlice;
157-
use clone::Clone;
158-
use ops::{Deref, FnOnce};
159+
use slice;
159160

160161
// Note that this is not a lang item per se, but it has a hidden dependency on
161162
// `Iterator`, which is one. The compiler assumes that the `next` method of
@@ -762,7 +763,6 @@ impl<T> AsSlice<T> for Option<T> {
762763

763764
#[stable]
764765
impl<T> Default for Option<T> {
765-
#[stable]
766766
#[inline]
767767
#[stable]
768768
fn default() -> Option<T> { None }

src/librustdoc/html/format.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub struct ConciseStability<'a>(pub &'a Option<clean::Stability>);
5151
pub struct WhereClause<'a>(pub &'a clean::Generics);
5252
/// Wrapper struct for emitting type parameter bounds.
5353
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
54+
/// Wrapper struct for emitting a comma-separated list of items
55+
pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
5456

5557
impl VisSpace {
5658
pub fn get(&self) -> Option<ast::Visibility> {
@@ -64,6 +66,16 @@ impl UnsafetySpace {
6466
}
6567
}
6668

69+
impl<'a, T: fmt::String> fmt::String for CommaSep<'a, T> {
70+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71+
for (i, item) in self.0.iter().enumerate() {
72+
if i != 0 { try!(write!(f, ", ")); }
73+
try!(write!(f, "{}", item));
74+
}
75+
Ok(())
76+
}
77+
}
78+
6779
impl<'a> fmt::String for TyParamBounds<'a> {
6880
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6981
let &TyParamBounds(bounds) = self;
@@ -450,7 +462,8 @@ impl fmt::String for clean::Type {
450462
lifetimes = if decl.lifetimes.len() == 0 {
451463
"".to_string()
452464
} else {
453-
format!("for &lt;{:#}&gt;", decl.lifetimes)
465+
format!("for &lt;{}&gt;",
466+
CommaSep(decl.lifetimes.as_slice()))
454467
},
455468
args = decl.decl.inputs,
456469
arrow = decl.decl.output,
@@ -482,7 +495,8 @@ impl fmt::String for clean::Type {
482495
lifetimes = if decl.lifetimes.len() == 0 {
483496
"".to_string()
484497
} else {
485-
format!("for &lt;{:#}&gt;", decl.lifetimes)
498+
format!("for &lt;{}&gt;",
499+
CommaSep(decl.lifetimes.as_slice()))
486500
},
487501
args = decl.decl.inputs,
488502
bounds = if decl.bounds.len() == 0 {
@@ -512,7 +526,8 @@ impl fmt::String for clean::Type {
512526
primitive_link(f, clean::PrimitiveTuple,
513527
match typs.as_slice() {
514528
[ref one] => format!("({},)", one),
515-
many => format!("({:#})", many)
529+
many => format!("({})",
530+
CommaSep(many.as_slice()))
516531
}.as_slice())
517532
}
518533
clean::Vector(ref t) => {

src/libstd/path/posix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn is_sep(c: char) -> bool {
6060

6161
impl fmt::Show for Path {
6262
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63-
write!(f, "Path {{ {} }}", self.display())
63+
fmt::Show::fmt(&self.display(), f)
6464
}
6565
}
6666

0 commit comments

Comments
 (0)