Skip to content

Commit d968340

Browse files
committed
auto merge of rust-lang#15281 : alexcrichton/rust/show-for-show, r=kballard
This makes printing a `Show` trait object much easier.
2 parents 5cef124 + 8bdc4b5 commit d968340

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libcore/fmt/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ impl<'a, T: Show> Show for &'a T {
518518
impl<'a, T: Show> Show for &'a mut T {
519519
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
520520
}
521+
impl<'a> Show for &'a Show {
522+
fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
523+
}
521524

522525
impl Bool for bool {
523526
fn fmt(&self, f: &mut Formatter) -> Result {

src/test/run-pass/ifmt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub fn main() {
8181
t!(format!("{foo_bar}", foo_bar=1i), "1");
8282
t!(format!("{:d}", 5i + 5i), "10");
8383

84+
let a: &fmt::Show = &1i;
85+
t!(format!("{}", a), "1");
86+
8487
// Formatting strings and their arguments
8588
t!(format!("{:s}", "a"), "a");
8689
t!(format!("{:4s}", "a"), "a ");

0 commit comments

Comments
 (0)