From 8bdc4b54a4a317d5b788f75179fed66d6cfdda8f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 30 Jun 2014 12:33:37 -0700 Subject: [PATCH] Add `impl Show for &Show` This makes printing a `Show` trait object much easier. --- src/libcore/fmt/mod.rs | 3 +++ src/test/run-pass/ifmt.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index ff7d7827fbb..7b84c005db5 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -518,6 +518,9 @@ fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) } impl<'a, T: Show> Show for &'a mut T { fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) } } +impl<'a> Show for &'a Show { + fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) } +} impl Bool for bool { fn fmt(&self, f: &mut Formatter) -> Result { diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 1258a498dac..e349f91a309 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -81,6 +81,9 @@ pub fn main() { t!(format!("{foo_bar}", foo_bar=1i), "1"); t!(format!("{:d}", 5i + 5i), "10"); + let a: &fmt::Show = &1i; + t!(format!("{}", a), "1"); + // Formatting strings and their arguments t!(format!("{:s}", "a"), "a"); t!(format!("{:4s}", "a"), "a "); -- 2.44.0