std: Tweak String implementations

This commit performs a pass over the implementations of the new `String` trait
in the formatting module. Some implementations were removed as a conservative
move pending an upcoming convention about `String` implementations, and some
were added in order to retain consistency across the libraries. Specifically:

* All "smart pointers" implement `String` now, adding missing implementations
  for `Arc` and `Rc`.
* The `Vec<T>` and `[T]` types no longer implement `String`.
* The `*const T` and `*mut T` type no longer implement `String`.
* The `()` type no longer implements `String`.
* The `Path` type's `Show` implementation does not surround itself with `Path
  {}` (a minor tweak).

All implementations of `String` in this PR were also marked `#[stable]` to
indicate that the types will continue to implement the `String` trait regardless
of what it looks like.
This commit is contained in:
Alex Crichton 2015-01-07 14:58:31 -08:00
parent 9f1ead8fad
commit 9851b4fbbf
22 changed files with 76 additions and 109 deletions

View file

@ -18,7 +18,7 @@ struct defer<'a> {
impl<'a> Drop for defer<'a> {
fn drop(&mut self) {
unsafe {
println!("{}", self.x);
println!("{:?}", self.x);
}
}
}

View file

@ -15,5 +15,5 @@ fn read_lines_borrowed<'a>() -> Vec<&'a str> {
}
fn main() {
println!("{}", read_lines_borrowed());
println!("{:?}", read_lines_borrowed());
}

View file

@ -23,5 +23,5 @@ fn main() {
assert_eq!((*arc_v)[2], 3);
println!("{}", *arc_v);
println!("{:?}", *arc_v);
}

View file

@ -21,5 +21,5 @@ fn main() {
assert_eq!((*arc_v)[2], 3); //~ ERROR use of moved value: `arc_v`
println!("{}", *arc_v); //~ ERROR use of moved value: `arc_v`
println!("{:?}", *arc_v); //~ ERROR use of moved value: `arc_v`
}

View file

@ -34,6 +34,6 @@ fn main() {
let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 };
unsafe {
let oof: Oof<[u8; 5], i32> = mem::transmute(foo);
println!("{} {}", &oof.rab[], oof.zab);
println!("{:?} {:?}", &oof.rab[], oof.zab);
}
}

View file

@ -22,7 +22,7 @@ pub fn main() {
let c : &[int] = &[2,2,2,2,3];
let cc : &[int] = &[2,2,2,2,2,2];
println!("{}", a);
println!("{:?}", a);
assert!(a < b);
assert!(a <= b);
@ -30,7 +30,7 @@ pub fn main() {
assert!(b >= a);
assert!(b > a);
println!("{}", b);
println!("{:?}", b);
assert!(b < c);
assert!(b <= c);
@ -44,7 +44,7 @@ pub fn main() {
assert!(c >= a);
assert!(c > a);
println!("{}", c);
println!("{:?}", c);
assert!(a < cc);
assert!(a <= cc);
@ -52,5 +52,5 @@ pub fn main() {
assert!(cc >= a);
assert!(cc > a);
println!("{}", cc);
println!("{:?}", cc);
}

View file

@ -183,7 +183,7 @@ fn test_write() {
// can do with them just yet (to test the output)
fn test_print() {
print!("hi");
print!("{}", vec!(0u8));
print!("{:?}", vec!(0u8));
println!("hello");
println!("this is a {}", "test");
println!("{foo}", foo="bar");

View file

@ -15,7 +15,7 @@ fn main() {
let ss: &&[int] = &s;
let sss: &&&[int] = &ss;
println!("{}", &s[0..3]);
println!("{}", &ss[3..]);
println!("{}", &sss[2..4]);
println!("{:?}", &s[0..3]);
println!("{:?}", &ss[3..]);
println!("{:?}", &sss[2..4]);
}

View file

@ -25,6 +25,6 @@ static V: &'static [X] = &[X { vec: &[1, 2, 3] }];
pub fn main() {
for &v in V.iter() {
println!("{}", v.vec);
println!("{:?}", v.vec);
}
}

View file

@ -16,8 +16,8 @@ pub fn main() {
print!("[");
for xi in x.iter() {
print!("{}, ", &xi[]);
print!("{:?}, ", &xi[]);
}
println!("]");
println!("{}", &y[]);
println!("{:?}", &y[]);
}

View file

@ -9,11 +9,11 @@
// except according to those terms.
pub fn main() {
assert_eq!((vec!(0i, 1)).to_string(), "[0, 1]".to_string());
assert_eq!(format!("{:?}", vec!(0i, 1)), "[0i, 1i]".to_string());
let foo = vec!(3i, 4);
let bar: &[int] = &[4, 5];
assert_eq!(foo.to_string(), "[3, 4]".to_string());
assert_eq!(bar.to_string(), "[4, 5]".to_string());
assert_eq!(format!("{:?}", foo), "[3i, 4i]");
assert_eq!(format!("{:?}", bar), "[4i, 5i]");
}