Skip to content

Commit 3cb9fa2

Browse files
committed
std: Rename Show/String to Debug/Display
This commit is an implementation of [RFC 565][rfc] which is a stabilization of the `std::fmt` module and the implementations of various formatting traits. Specifically, the following changes were performed: [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md * The `Show` trait is now deprecated, it was renamed to `Debug` * The `String` trait is now deprecated, it was renamed to `Display` * Many `Debug` and `Display` implementations were audited in accordance with the RFC and audited implementations now have the `#[stable]` attribute * Integers and floats no longer print a suffix * Smart pointers no longer print details that they are a smart pointer * Paths with `Debug` are now quoted and escape characters * The `unwrap` methods on `Result` now require `Display` instead of `Debug` * The `Error` trait no longer has a `detail` method and now requires that `Display` must be implemented. With the loss of `String`, this has moved into libcore. * `impl<E: Error> FromError<E> for Box<Error>` now exists * `derive(Show)` has been renamed to `derive(Debug)`. This is not currently warned about due to warnings being emitted on stage1+ While backwards compatibility is attempted to be maintained with a blanket implementation of `Display` for the old `String` trait (and the same for `Show`/`Debug`) this is still a breaking change due to primitives no longer implementing `String` as well as modifications such as `unwrap` and the `Error` trait. Most code is fairly straightforward to update with a rename or tweaks of method calls. [breaking-change] Closes #21436
1 parent 29bd9a0 commit 3cb9fa2

File tree

136 files changed

+763
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+763
-706
lines changed

src/compiletest/common.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fmt;
1313
use std::str::FromStr;
1414
use regex::Regex;
1515

16-
#[derive(Clone, PartialEq)]
16+
#[derive(Clone, PartialEq, Debug)]
1717
pub enum Mode {
1818
CompileFail,
1919
RunFail,
@@ -43,9 +43,9 @@ impl FromStr for Mode {
4343
}
4444
}
4545

46-
impl fmt::String for Mode {
46+
impl fmt::Display for Mode {
4747
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48-
fmt::String::fmt(match *self {
48+
fmt::Display::fmt(match *self {
4949
CompileFail => "compile-fail",
5050
RunFail => "run-fail",
5151
RunPass => "run-pass",
@@ -58,12 +58,6 @@ impl fmt::String for Mode {
5858
}
5959
}
6060

61-
impl fmt::Show for Mode {
62-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63-
fmt::String::fmt(self, f)
64-
}
65-
}
66-
6761
#[derive(Clone)]
6862
pub struct Config {
6963
// The library paths required for running the compiler

src/compiletest/runtest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
547547

548548
// Add line breakpoints
549549
for line in breakpoint_lines.iter() {
550-
script_str.push_str(&format!("break '{:?}':{}\n",
550+
script_str.push_str(&format!("break '{}':{}\n",
551551
testfile.filename_display(),
552552
*line)[]);
553553
}
@@ -750,7 +750,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
750750
status: status,
751751
stdout: out,
752752
stderr: err,
753-
cmdline: format!("{}", cmd)
753+
cmdline: format!("{:?}", cmd)
754754
};
755755
}
756756
}
@@ -953,7 +953,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
953953
}
954954

955955
let prefixes = expected_errors.iter().map(|ee| {
956-
format!("{:?}:{}:", testfile.display(), ee.line)
956+
format!("{}:{}:", testfile.display(), ee.line)
957957
}).collect::<Vec<String> >();
958958

959959
#[cfg(windows)]

src/liballoc/arc.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use core::prelude::*;
7272
use core::atomic;
7373
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
7474
use core::borrow::BorrowFrom;
75-
use core::fmt::{self, Show};
75+
use core::fmt;
7676
use core::cmp::{Ordering};
7777
use core::default::Default;
7878
use core::mem::{min_align_of, size_of};
@@ -578,16 +578,17 @@ impl<T: Ord> Ord for Arc<T> {
578578
#[stable]
579579
impl<T: Eq> Eq for Arc<T> {}
580580

581-
impl<T: fmt::Show> fmt::Show for Arc<T> {
581+
#[stable]
582+
impl<T: fmt::Display> fmt::Display for Arc<T> {
582583
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
583-
write!(f, "Arc({:?})", (**self))
584+
fmt::Display::fmt(&**self, f)
584585
}
585586
}
586587

587588
#[stable]
588-
impl<T: fmt::String> fmt::String for Arc<T> {
589+
impl<T: fmt::Debug> fmt::Debug for Arc<T> {
589590
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
590-
fmt::String::fmt(&**self, f)
591+
fmt::Debug::fmt(&**self, f)
591592
}
592593
}
593594

@@ -806,7 +807,7 @@ mod tests {
806807
#[test]
807808
fn show_arc() {
808809
let a = Arc::new(5u32);
809-
assert!(format!("{:?}", a) == "Arc(5u32)")
810+
assert_eq!(format!("{:?}", a), "5");
810811
}
811812

812813
// Make sure deriving works with Arc<T>

src/liballoc/boxed.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ use core::any::Any;
1616
use core::clone::Clone;
1717
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
1818
use core::default::Default;
19+
use core::error::{Error, FromError};
1920
use core::fmt;
2021
use core::hash::{self, Hash};
2122
use core::marker::Sized;
2223
use core::mem;
24+
use core::ops::{Deref, DerefMut};
2325
use core::option::Option;
2426
use core::ptr::Unique;
2527
use core::raw::TraitObject;
26-
use core::result::Result;
2728
use core::result::Result::{Ok, Err};
28-
use core::ops::{Deref, DerefMut};
29+
use core::result::Result;
2930

3031
/// A value that represents the global exchange heap. This is the default
3132
/// place that the `box` keyword allocates into when no place is supplied.
@@ -156,20 +157,22 @@ impl BoxAny for Box<Any> {
156157
}
157158
}
158159

159-
impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
160+
#[stable]
161+
impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> {
160162
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161-
write!(f, "Box({:?})", &**self)
163+
fmt::Display::fmt(&**self, f)
162164
}
163165
}
164166

165167
#[stable]
166-
impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
168+
impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
167169
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
168-
fmt::String::fmt(&**self, f)
170+
fmt::Debug::fmt(&**self, f)
169171
}
170172
}
171173

172-
impl fmt::Show for Box<Any> {
174+
#[stable]
175+
impl fmt::Debug for Box<Any> {
173176
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
174177
f.pad("Box<Any>")
175178
}
@@ -187,6 +190,12 @@ impl<T: ?Sized> DerefMut for Box<T> {
187190
fn deref_mut(&mut self) -> &mut T { &mut **self }
188191
}
189192

193+
impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
194+
fn from_error(err: E) -> Box<Error + 'a> {
195+
Box::new(err)
196+
}
197+
}
198+
190199
#[cfg(test)]
191200
mod test {
192201
#[test]

src/liballoc/rc.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,17 @@ impl<S: hash::Hasher, T: Hash<S>> Hash<S> for Rc<T> {
693693
}
694694
}
695695

696-
#[unstable = "Show is experimental."]
697-
impl<T: fmt::Show> fmt::Show for Rc<T> {
696+
#[stable]
697+
impl<T: fmt::Display> fmt::Display for Rc<T> {
698698
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
699-
write!(f, "Rc({:?})", **self)
699+
fmt::Display::fmt(&**self, f)
700700
}
701701
}
702702

703703
#[stable]
704-
impl<T: fmt::String> fmt::String for Rc<T> {
704+
impl<T: fmt::Debug> fmt::Debug for Rc<T> {
705705
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
706-
fmt::String::fmt(&**self, f)
706+
fmt::Debug::fmt(&**self, f)
707707
}
708708
}
709709

@@ -890,8 +890,8 @@ impl<T> Clone for Weak<T> {
890890
}
891891
}
892892

893-
#[unstable = "Show is experimental."]
894-
impl<T: fmt::Show> fmt::Show for Weak<T> {
893+
#[stable]
894+
impl<T: fmt::Debug> fmt::Debug for Weak<T> {
895895
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
896896
write!(f, "(Weak)")
897897
}
@@ -1134,7 +1134,7 @@ mod tests {
11341134
#[test]
11351135
fn test_show() {
11361136
let foo = Rc::new(75u);
1137-
assert!(format!("{:?}", foo) == "Rc(75u)")
1137+
assert_eq!(format!("{:?}", foo), "75");
11381138
}
11391139

11401140
}

src/libcollections/bit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ impl Ord for Bitv {
972972
}
973973

974974
#[stable]
975-
impl fmt::Show for Bitv {
975+
impl fmt::Debug for Bitv {
976976
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
977977
for bit in self.iter() {
978978
try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 }));
@@ -1727,7 +1727,7 @@ impl BitvSet {
17271727
}
17281728
}
17291729

1730-
impl fmt::Show for BitvSet {
1730+
impl fmt::Debug for BitvSet {
17311731
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
17321732
try!(write!(fmt, "BitvSet {{"));
17331733
let mut first = true;
@@ -2622,7 +2622,7 @@ mod bitv_set_test {
26222622
s.insert(10);
26232623
s.insert(50);
26242624
s.insert(2);
2625-
assert_eq!("BitvSet {1u, 2u, 10u, 50u}", format!("{:?}", s));
2625+
assert_eq!("BitvSet {1, 2, 10, 50}", format!("{:?}", s));
26262626
}
26272627

26282628
#[test]

src/libcollections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use core::prelude::*;
2222
use core::borrow::BorrowFrom;
2323
use core::cmp::Ordering;
2424
use core::default::Default;
25-
use core::fmt::Show;
25+
use core::fmt::Debug;
2626
use core::hash::{Hash, Hasher};
2727
use core::iter::{Map, FromIterator};
2828
use core::ops::{Index, IndexMut};
@@ -871,7 +871,7 @@ impl<K: Ord, V: Ord> Ord for BTreeMap<K, V> {
871871
}
872872

873873
#[stable]
874-
impl<K: Show, V: Show> Show for BTreeMap<K, V> {
874+
impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
875875
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
876876
try!(write!(f, "BTreeMap {{"));
877877

src/libcollections/btree/set.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use core::prelude::*;
1616
use core::borrow::BorrowFrom;
1717
use core::cmp::Ordering::{self, Less, Greater, Equal};
1818
use core::default::Default;
19-
use core::fmt::Show;
19+
use core::fmt::Debug;
2020
use core::fmt;
2121
// NOTE(stage0) remove import after a snapshot
2222
#[cfg(stage0)]
@@ -592,7 +592,7 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
592592
}
593593

594594
#[stable]
595-
impl<T: Show> Show for BTreeSet<T> {
595+
impl<T: Debug> Debug for BTreeSet<T> {
596596
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
597597
try!(write!(f, "BTreeSet {{"));
598598

@@ -892,7 +892,7 @@ mod test {
892892

893893
let set_str = format!("{:?}", set);
894894

895-
assert_eq!(set_str, "BTreeSet {1i, 2i}");
895+
assert_eq!(set_str, "BTreeSet {1, 2}");
896896
assert_eq!(format!("{:?}", empty), "BTreeSet {}");
897897
}
898898
}

src/libcollections/dlist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ impl<A: Clone> Clone for DList<A> {
874874
}
875875

876876
#[stable]
877-
impl<A: fmt::Show> fmt::Show for DList<A> {
877+
impl<A: fmt::Debug> fmt::Debug for DList<A> {
878878
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
879879
try!(write!(f, "DList ["));
880880

@@ -1333,7 +1333,7 @@ mod tests {
13331333
#[test]
13341334
fn test_show() {
13351335
let list: DList<int> = range(0i, 10).collect();
1336-
assert_eq!(format!("{:?}", list), "DList [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]");
1336+
assert_eq!(format!("{:?}", list), "DList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
13371337

13381338
let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
13391339
.map(|&s| s)

src/libcollections/enum_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct EnumSet<E> {
3131

3232
impl<E> Copy for EnumSet<E> {}
3333

34-
impl<E:CLike+fmt::Show> fmt::Show for EnumSet<E> {
34+
impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
3535
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
3636
try!(write!(fmt, "EnumSet {{"));
3737
let mut first = true;

src/libcollections/ring_buf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl<A> Extend<A> for RingBuf<A> {
16111611
}
16121612

16131613
#[stable]
1614-
impl<T: fmt::Show> fmt::Show for RingBuf<T> {
1614+
impl<T: fmt::Debug> fmt::Debug for RingBuf<T> {
16151615
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16161616
try!(write!(f, "RingBuf ["));
16171617

@@ -1630,7 +1630,7 @@ mod tests {
16301630
use self::Taggypar::*;
16311631
use prelude::*;
16321632
use core::iter;
1633-
use std::fmt::Show;
1633+
use std::fmt::Debug;
16341634
use std::hash::{self, SipHasher};
16351635
use test::Bencher;
16361636
use test;
@@ -1678,7 +1678,7 @@ mod tests {
16781678
}
16791679

16801680
#[cfg(test)]
1681-
fn test_parameterized<T:Clone + PartialEq + Show>(a: T, b: T, c: T, d: T) {
1681+
fn test_parameterized<T:Clone + PartialEq + Debug>(a: T, b: T, c: T, d: T) {
16821682
let mut deq = RingBuf::new();
16831683
assert_eq!(deq.len(), 0);
16841684
deq.push_front(a.clone());
@@ -2302,7 +2302,7 @@ mod tests {
23022302
#[test]
23032303
fn test_show() {
23042304
let ringbuf: RingBuf<int> = range(0i, 10).collect();
2305-
assert_eq!(format!("{:?}", ringbuf), "RingBuf [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]");
2305+
assert_eq!(format!("{:?}", ringbuf), "RingBuf [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
23062306

23072307
let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter()
23082308
.map(|&s| s)

src/libcollections/slice.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2476,19 +2476,19 @@ mod tests {
24762476
}
24772477
let empty: Vec<int> = vec![];
24782478
test_show_vec!(empty, "[]");
2479-
test_show_vec!(vec![1i], "[1i]");
2480-
test_show_vec!(vec![1i, 2, 3], "[1i, 2i, 3i]");
2479+
test_show_vec!(vec![1i], "[1]");
2480+
test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]");
24812481
test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]],
2482-
"[[], [1u], [1u, 1u]]");
2482+
"[[], [1], [1, 1]]");
24832483

24842484
let empty_mut: &mut [int] = &mut[];
24852485
test_show_vec!(empty_mut, "[]");
24862486
let v: &mut[int] = &mut[1];
2487-
test_show_vec!(v, "[1i]");
2487+
test_show_vec!(v, "[1]");
24882488
let v: &mut[int] = &mut[1, 2, 3];
2489-
test_show_vec!(v, "[1i, 2i, 3i]");
2489+
test_show_vec!(v, "[1, 2, 3]");
24902490
let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]];
2491-
test_show_vec!(v, "[[], [1u], [1u, 1u]]");
2491+
test_show_vec!(v, "[[], [1], [1, 1]]");
24922492
}
24932493

24942494
#[test]

0 commit comments

Comments
 (0)