Skip to content

Commit 8bdc4b5

Browse files
committed
Add impl Show for &Show
This makes printing a `Show` trait object much easier.
1 parent 566b57f commit 8bdc4b5

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libcore/fmt/mod.rs

+3
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

+3
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)