Skip to content

Commit 065caf3

Browse files
committed
auto merge of #18431 : japaric/rust/show, r=alexcrichton
r? @aturon cc #16918
2 parents 221fc1e + eef7e97 commit 065caf3

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

src/liballoc/boxed.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
1616
use core::default::Default;
1717
use core::fmt;
1818
use core::intrinsics;
19+
use core::kinds::Sized;
1920
use core::mem;
2021
use core::option::Option;
2122
use core::raw::TraitObject;
@@ -120,7 +121,7 @@ impl BoxAny for Box<Any+'static> {
120121
}
121122
}
122123

123-
impl<T: fmt::Show> fmt::Show for Box<T> {
124+
impl<Sized? T: fmt::Show> fmt::Show for Box<T> {
124125
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125126
(**self).fmt(f)
126127
}

src/libcore/fmt/mod.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use any;
1616
use cell::{Cell, Ref, RefMut};
1717
use collections::Collection;
1818
use iter::{Iterator, range};
19-
use kinds::Copy;
19+
use kinds::{Copy, Sized};
2020
use mem;
2121
use option::{Option, Some, None};
2222
use ops::Deref;
@@ -168,85 +168,85 @@ impl<'a> Show for Arguments<'a> {
168168
/// When a format is not otherwise specified, types are formatted by ascribing
169169
/// to this trait. There is not an explicit way of selecting this trait to be
170170
/// used for formatting, it is only if no other format is specified.
171-
pub trait Show {
171+
pub trait Show for Sized? {
172172
/// Formats the value using the given formatter.
173173
fn fmt(&self, &mut Formatter) -> Result;
174174
}
175175

176176
/// Format trait for the `b` character
177-
pub trait Bool {
177+
pub trait Bool for Sized? {
178178
/// Formats the value using the given formatter.
179179
fn fmt(&self, &mut Formatter) -> Result;
180180
}
181181

182182
/// Format trait for the `c` character
183-
pub trait Char {
183+
pub trait Char for Sized? {
184184
/// Formats the value using the given formatter.
185185
fn fmt(&self, &mut Formatter) -> Result;
186186
}
187187

188188
/// Format trait for the `i` and `d` characters
189-
pub trait Signed {
189+
pub trait Signed for Sized? {
190190
/// Formats the value using the given formatter.
191191
fn fmt(&self, &mut Formatter) -> Result;
192192
}
193193

194194
/// Format trait for the `u` character
195-
pub trait Unsigned {
195+
pub trait Unsigned for Sized? {
196196
/// Formats the value using the given formatter.
197197
fn fmt(&self, &mut Formatter) -> Result;
198198
}
199199

200200
/// Format trait for the `o` character
201-
pub trait Octal {
201+
pub trait Octal for Sized? {
202202
/// Formats the value using the given formatter.
203203
fn fmt(&self, &mut Formatter) -> Result;
204204
}
205205

206206
/// Format trait for the `t` character
207-
pub trait Binary {
207+
pub trait Binary for Sized? {
208208
/// Formats the value using the given formatter.
209209
fn fmt(&self, &mut Formatter) -> Result;
210210
}
211211

212212
/// Format trait for the `x` character
213-
pub trait LowerHex {
213+
pub trait LowerHex for Sized? {
214214
/// Formats the value using the given formatter.
215215
fn fmt(&self, &mut Formatter) -> Result;
216216
}
217217

218218
/// Format trait for the `X` character
219-
pub trait UpperHex {
219+
pub trait UpperHex for Sized? {
220220
/// Formats the value using the given formatter.
221221
fn fmt(&self, &mut Formatter) -> Result;
222222
}
223223

224224
/// Format trait for the `s` character
225-
pub trait String {
225+
pub trait String for Sized? {
226226
/// Formats the value using the given formatter.
227227
fn fmt(&self, &mut Formatter) -> Result;
228228
}
229229

230230
/// Format trait for the `p` character
231-
pub trait Pointer {
231+
pub trait Pointer for Sized? {
232232
/// Formats the value using the given formatter.
233233
fn fmt(&self, &mut Formatter) -> Result;
234234
}
235235

236236
/// Format trait for the `f` character
237-
pub trait Float {
237+
pub trait Float for Sized? {
238238
/// Formats the value using the given formatter.
239239
fn fmt(&self, &mut Formatter) -> Result;
240240
}
241241

242242
/// Format trait for the `e` character
243-
pub trait LowerExp {
243+
pub trait LowerExp for Sized? {
244244
/// Formats the value using the given formatter.
245245
fn fmt(&self, &mut Formatter) -> Result;
246246
}
247247

248248
/// Format trait for the `E` character
249-
pub trait UpperExp {
249+
pub trait UpperExp for Sized? {
250250
/// Formats the value using the given formatter.
251251
fn fmt(&self, &mut Formatter) -> Result;
252252
}
@@ -257,7 +257,7 @@ macro_rules! uniform_fn_call_workaround {
257257
($( $name: ident, $trait_: ident; )*) => {
258258
$(
259259
#[doc(hidden)]
260-
pub fn $name<T: $trait_>(x: &T, fmt: &mut Formatter) -> Result {
260+
pub fn $name<Sized? T: $trait_>(x: &T, fmt: &mut Formatter) -> Result {
261261
x.fmt(fmt)
262262
}
263263
)*
@@ -583,10 +583,10 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
583583

584584
// Implementations of the core formatting traits
585585

586-
impl<'a, T: Show> Show for &'a T {
586+
impl<'a, Sized? T: Show> Show for &'a T {
587587
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
588588
}
589-
impl<'a, T: Show> Show for &'a mut T {
589+
impl<'a, Sized? T: Show> Show for &'a mut T {
590590
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
591591
}
592592
impl<'a> Show for &'a Show+'a {
@@ -599,12 +599,18 @@ impl Bool for bool {
599599
}
600600
}
601601

602-
impl<'a, T: str::Str> String for T {
602+
impl<T: str::Str> String for T {
603603
fn fmt(&self, f: &mut Formatter) -> Result {
604604
f.pad(self.as_slice())
605605
}
606606
}
607607

608+
impl String for str {
609+
fn fmt(&self, f: &mut Formatter) -> Result {
610+
f.pad(self)
611+
}
612+
}
613+
608614
impl Char for char {
609615
fn fmt(&self, f: &mut Formatter) -> Result {
610616
use char::Char;
@@ -708,13 +714,13 @@ floating!(f64)
708714
// Implementation of Show for various core types
709715

710716
macro_rules! delegate(($ty:ty to $other:ident) => {
711-
impl<'a> Show for $ty {
717+
impl Show for $ty {
712718
fn fmt(&self, f: &mut Formatter) -> Result {
713719
(concat_idents!(secret_, $other)(self, f))
714720
}
715721
}
716722
})
717-
delegate!(&'a str to string)
723+
delegate!(str to string)
718724
delegate!(bool to bool)
719725
delegate!(char to char)
720726
delegate!(f32 to float)
@@ -761,7 +767,7 @@ impl<'a> Show for &'a any::Any+'a {
761767
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
762768
}
763769

764-
impl<'a, T: Show> Show for &'a [T] {
770+
impl<T: Show> Show for [T] {
765771
fn fmt(&self, f: &mut Formatter) -> Result {
766772
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
767773
try!(write!(f, "["));
@@ -782,12 +788,6 @@ impl<'a, T: Show> Show for &'a [T] {
782788
}
783789
}
784790

785-
impl<'a, T: Show> Show for &'a mut [T] {
786-
fn fmt(&self, f: &mut Formatter) -> Result {
787-
secret_show(&self.as_slice(), f)
788-
}
789-
}
790-
791791
impl Show for () {
792792
fn fmt(&self, f: &mut Formatter) -> Result {
793793
f.pad("()")

src/test/run-pass/show-boxed-slice.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Show)]
12+
struct Foo(Box<[u8]>);
13+
14+
pub fn main() {
15+
println!("{}", Foo(box [0, 1, 2]));
16+
}

0 commit comments

Comments
 (0)