core: split into fmt::Show and fmt::String

fmt::Show is for debugging, and can and should be implemented for
all public types. This trait is used with `{:?}` syntax. There still
exists #[derive(Show)].

fmt::String is for types that faithfully be represented as a String.
Because of this, there is no way to derive fmt::String, all
implementations must be purposeful. It is used by the default format
syntax, `{}`.

This will break most instances of `{}`, since that now requires the type
to impl fmt::String. In most cases, replacing `{}` with `{:?}` is the
correct fix. Types that were being printed specifically for users should
receive a fmt::String implementation to fix this.

Part of #20013

[breaking-change]
This commit is contained in:
Sean McArthur 2014-12-20 00:09:35 -08:00
parent 8efd9901b6
commit 44440e5c18
252 changed files with 1996 additions and 1366 deletions

View file

@ -17,7 +17,7 @@ pub mod kitty {
pub name : String,
}
impl fmt::Show for cat {
impl fmt::String for cat {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)
}

View file

@ -35,7 +35,7 @@ pub fn main() {
}
}
let z = tail[0].clone();
println!("{}", z);
println!("{:?}", z);
}
_ => {
unreachable!();

View file

@ -27,5 +27,5 @@ fn main() {
let x = foo(10);
let _y = x.clone();
//~^ ERROR does not implement any method in scope
println!("{}", x);
println!("{:?}", x);
}

View file

@ -46,7 +46,7 @@ fn main() {
// bad syntax of the format string
format!("{"); //~ ERROR: expected `}` but string was terminated
format!("{"); //~ ERROR: expected `'}'` but string was terminated
format!("foo } bar"); //~ ERROR: unmatched `}` found
format!("foo }"); //~ ERROR: unmatched `}` found

View file

@ -27,5 +27,5 @@ impl Something for X {
fn main() {
let arr = &["one", "two", "three"];
println!("{}", Something::yay(None::<X>, arr));
println!("{:?}", Something::yay(None::<X>, arr));
}

View file

@ -19,7 +19,7 @@ struct Shower<T> {
impl<T: fmt::Show> ops::Fn<(), ()> for Shower<T> {
fn call(&self, _args: ()) {
//~^ ERROR `call` has an incompatible type for trait: expected "rust-call" fn, found "Rust" fn
println!("{}", self.x);
println!("{:?}", self.x);
}
}

View file

@ -123,8 +123,8 @@ fn str_to_direction(to_parse: &str) -> RoomDirection {
fn main() {
let mut player = Player::new("Test player");
let mut room = Room::new("A test room");
println!("Made a player: {}", player);
println!("Direction parse: {}", str_to_direction("east"));
println!("Made a player: {:?}", player);
println!("Direction parse: {:?}", str_to_direction("east"));
match player.attemptTraverse(&room, "west") {
Ok(_) => println!("Was able to move west"),
Err(msg) => println!("Not able to move west: {}", msg)

View file

@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() { format!("{}", None); }
fn main() { format!("{:?}", None); }
//~^ ERROR type annotations required

View file

@ -10,6 +10,6 @@
fn main() {
// Unconstrained type:
format!("{}", None);
format!("{:?}", None);
//~^ ERROR type annotations required
}

View file

@ -16,6 +16,6 @@ extern {
}
fn main() {
println!("{}", foo);
println!("{:?}", foo);
}

View file

@ -32,7 +32,7 @@ fn main() {
let mut buff = [0u8; 16];
match f.read(&mut buff) {
Ok(cnt) => println!("read this many bytes: {}", cnt),
Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {}", EndOfFile.to_string()),
Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {:?}", EndOfFile),
//~^ ERROR variable `EndOfFile` should have a snake case name such as `end_of_file`
//~^^ WARN `EndOfFile` is named the same as one of the variants of the type `std::io::IoErrorKind`
}

View file

@ -9,8 +9,8 @@
// except according to those terms.
fn send<T:Send + std::fmt::Show>(ch: _chan<T>, data: T) {
println!("{}", ch);
println!("{}", data);
println!("{:?}", ch);
println!("{:?}", data);
panic!();
}

View file

@ -39,6 +39,6 @@ fn main() {
//~^ ERROR `core::kinds::Send` is not implemented
//~^^ ERROR `core::kinds::Send` is not implemented
let y = x;
println!("{}", y);
println!("{:?}", y);
});
}

View file

@ -42,5 +42,5 @@ fn foo(i:int) -> foo {
fn main() {
let x = foo(10);
let _y = x.clone(); //~ ERROR does not implement any method in scope
println!("{}", x);
println!("{:?}", x);
}

View file

@ -33,6 +33,6 @@ fn main() {
let foo = Foo { bar: 1, baz: 10 };
unsafe {
let oof: Oof = mem::transmute(foo);
println!("{}", oof);
println!("{:?}", oof);
}
}

View file

@ -53,9 +53,9 @@ fn state_iter() -> StateMachineIter<'static> {
fn main() {
let mut it = state_iter();
println!("{}",it.next());
println!("{}",it.next());
println!("{}",it.next());
println!("{}",it.next());
println!("{}",it.next());
println!("{:?}",it.next());
println!("{:?}",it.next());
println!("{:?}",it.next());
println!("{:?}",it.next());
println!("{:?}",it.next());
}

View file

@ -20,5 +20,5 @@ impl Drop for r {
fn main() {
let i = box r { b: true };
let _j = i.clone(); //~ ERROR not implement
println!("{}", i);
println!("{:?}", i);
}

View file

@ -39,6 +39,6 @@ fn main() {
f(clone(&r1), clone(&r2));
//~^ ERROR the trait `core::clone::Clone` is not implemented for the type
//~^^ ERROR the trait `core::clone::Clone` is not implemented for the type
println!("{}", (r2, i1.get()));
println!("{}", (r1, i2.get()));
println!("{:?}", (r2, i1.get()));
println!("{:?}", (r1, i2.get()));
}

View file

@ -16,7 +16,7 @@ struct Number {
n: i64
}
impl fmt::Show for Number {
impl fmt::String for Number {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.n)
}

View file

@ -25,5 +25,5 @@ fn main() {
let j = vec!(r(1));
let k = i + j;
//~^ ERROR binary operation `+` cannot be applied to type
println!("{}", j);
println!("{:?}", j);
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:assertion failed: `(left == right) && (right == left)` (left: `14`, right: `15`)
// error-pattern:assertion failed: `(left == right) && (right == left)` (left: `14i`, right: `15i`)
fn main() {
assert_eq!(14i,15i);

View file

@ -32,9 +32,9 @@ pub fn main() {
add_int(&mut *ints, 44);
iter_ints(&*ints, |i| {
println!("int = {}", *i);
println!("int = {:?}", *i);
true
});
println!("ints={}", ints);
println!("ints={:?}", ints);
}

View file

@ -51,7 +51,7 @@ fn cat(in_x : uint, in_y : int, in_name: String) -> cat {
}
}
impl fmt::Show for cat {
impl fmt::String for cat {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)
}

View file

@ -16,5 +16,5 @@ extern crate log;
pub fn main() {
// only panics if println! evaluates its argument.
debug!("{}", { if true { panic!() } });
debug!("{:?}", { if true { panic!() } });
}

View file

@ -13,7 +13,7 @@
pub fn main() {
// exits early if println! evaluates its arguments, otherwise it
// will hit the panic.
println!("{}", { if true { return; } });
println!("{:?}", { if true { return; } });
panic!();
}

View file

@ -15,5 +15,5 @@ pub fn main() {
}
let f = Foo { foo: 10 };
format!("{}", f);
format!("{:?}", f);
}

View file

@ -38,16 +38,25 @@ impl fmt::Show for Custom {
}
}
pub fn main() {
assert_eq!(B::B1.to_string(), "B1".to_string());
assert_eq!(B::B2.to_string(), "B2".to_string());
assert_eq!(C::C1(3).to_string(), "C1(3)".to_string());
assert_eq!(C::C2(B::B2).to_string(), "C2(B2)".to_string());
assert_eq!(D::D1{ a: 2 }.to_string(), "D1 { a: 2 }".to_string());
assert_eq!(E.to_string(), "E".to_string());
assert_eq!(F(3).to_string(), "F(3)".to_string());
assert_eq!(G(3, 4).to_string(), "G(3, 4)".to_string());
assert_eq!(G(3, 4).to_string(), "G(3, 4)".to_string());
assert_eq!(I{ a: 2, b: 4 }.to_string(), "I { a: 2, b: 4 }".to_string());
assert_eq!(J(Custom).to_string(), "J(yay)".to_string());
trait ToShow {
fn to_show(&self) -> String;
}
impl<T: fmt::Show> ToShow for T {
fn to_show(&self) -> String {
format!("{:?}", self)
}
}
pub fn main() {
assert_eq!(B::B1.to_show(), "B1".to_string());
assert_eq!(B::B2.to_show(), "B2".to_string());
assert_eq!(C::C1(3).to_show(), "C1(3i)".to_string());
assert_eq!(C::C2(B::B2).to_show(), "C2(B2)".to_string());
assert_eq!(D::D1{ a: 2 }.to_show(), "D1 { a: 2i }".to_string());
assert_eq!(E.to_show(), "E".to_string());
assert_eq!(F(3).to_show(), "F(3i)".to_string());
assert_eq!(G(3, 4).to_show(), "G(3i, 4i)".to_string());
assert_eq!(I{ a: 2, b: 4 }.to_show(), "I { a: 2i, b: 4i }".to_string());
assert_eq!(J(Custom).to_show(), "J(yay)".to_string());
}

View file

@ -26,15 +26,15 @@ enum Enum {
macro_rules! t {
($x:expr, $expected:expr) => {
assert_eq!(format!("{}", $x), $expected.to_string())
assert_eq!(format!("{:?}", $x), $expected.to_string())
}
}
pub fn main() {
t!(Unit, "Unit");
t!(Tuple(1, 2), "Tuple(1, 2)");
t!(Struct { x: 1, y: 2 }, "Struct { x: 1, y: 2 }");
t!(Tuple(1, 2), "Tuple(1i, 2u)");
t!(Struct { x: 1, y: 2 }, "Struct { x: 1i, y: 2u }");
t!(Enum::Nullary, "Nullary");
t!(Enum::Variant(1, 2), "Variant(1, 2)");
t!(Enum::StructVariant { x: 1, y: 2 }, "StructVariant { x: 1, y: 2 }");
t!(Enum::Variant(1, 2), "Variant(1i, 2u)");
t!(Enum::StructVariant { x: 1, y: 2 }, "StructVariant { x: 1i, y: 2u }");
}

View file

@ -37,5 +37,5 @@ impl Index<uint> for T {
fn main() {
assert_eq!(&S[0], "hello");
assert_eq!(format!("{}", &T[0]).as_slice(), "42");
assert_eq!(format!("{:?}", &T[0]), "42u");
}

View file

@ -23,8 +23,8 @@ macro_rules! check {
assert_eq!(size_of::<E>(), size_of::<$t>());
assert_eq!(E::V as $t, $v as $t);
assert_eq!(C as $t, $v as $t);
assert_eq!(format!("{}", E::V), "V".to_string());
assert_eq!(format!("{}", C), "V".to_string());
assert_eq!(format!("{:?}", E::V), "V".to_string());
assert_eq!(format!("{:?}", C), "V".to_string());
}
}
$m::check();

View file

@ -17,5 +17,5 @@ struct Foo {
pub fn main() {
let a = Foo { x: 1, y: 2 };
let c = Foo { x: 4, .. a};
println!("{}", c);
println!("{:?}", c);
}

View file

@ -30,7 +30,7 @@ impl fmt::UpperHex for B {
f.write_str("adios")
}
}
impl fmt::Show for C {
impl fmt::String for C {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad_integral(true, "", "123")
}
@ -58,9 +58,12 @@ pub fn main() {
t!(format!("{}", true), "true");
t!(format!("{}", '☃'), "");
t!(format!("{}", 10i), "10");
t!(format!("{}", 10i), "10");
t!(format!("{}", 10u), "10");
t!(format!("{:?}", true), "true");
t!(format!("{:?}", '☃'), "'\\u{2603}'");
t!(format!("{:?}", 10i), "10i");
t!(format!("{:?}", 10u), "10u");
t!(format!("{:?}", "true"), "\"true\"");
t!(format!("{:?}", "foo\nbar"), "\"foo\\nbar\"");
t!(format!("{:o}", 10u), "12");
t!(format!("{:x}", 10u), "a");
t!(format!("{:X}", 10u), "A");
@ -80,7 +83,8 @@ pub fn main() {
t!(format!("{:#4}", C), "☃123");
let a: &fmt::Show = &1i;
t!(format!("{}", a), "1");
t!(format!("{:?}", a), "1i");
// Formatting strings and their arguments
t!(format!("{}", "a"), "a");

View file

@ -15,7 +15,7 @@ enum Foo<'s> {
fn f(arr: &[&Foo]) {
for &f in arr.iter() {
println!("{}", f);
println!("{:?}", f);
}
}

View file

@ -30,5 +30,5 @@ pub fn main () {
let mut p = process::Command::new(args[0].as_slice());
p.arg("child").stdout(process::Ignored).stderr(process::Ignored);
println!("{}", p.spawn().unwrap().wait());
println!("{:?}", p.spawn().unwrap().wait());
}

View file

@ -20,7 +20,7 @@ impl T<int> for Empty {
}
fn do_something_with(a : &mut T<int>) {
println!("{}", a.next())
println!("{:?}", a.next())
}
pub fn main() {

View file

@ -10,5 +10,5 @@
fn main() {
fn test() -> Box<std::any::Any + 'static> { box 1i }
println!("{}", test())
println!("{:?}", test())
}

View file

@ -26,5 +26,5 @@ fn do_stuff<R: Repro>(r: R) -> String {
}
pub fn main() {
assert_eq!("MyStruct".to_string(), do_stuff(|: s: MyStruct| format!("{}", s)));
assert_eq!("MyStruct".to_string(), do_stuff(|: s: MyStruct| format!("{:?}", s)));
}

View file

@ -15,5 +15,5 @@ use std::collections::HashMap;
pub fn main() {
let mut m = HashMap::new();
m.insert(b"foo".to_vec(), b"bar".to_vec());
println!("{}", m);
println!("{:?}", m);
}

View file

@ -14,7 +14,7 @@
struct LifetimeStruct<'a>;
fn main() {
takes_hrtb_closure(|&mut: lts| println!("{}", lts));
takes_hrtb_closure(|&mut: lts| println!("{:?}", lts));
}
fn takes_hrtb_closure<F: for<'a>FnMut(LifetimeStruct<'a>)>(mut f: F) {

View file

@ -25,5 +25,5 @@ impl Trait for int {}
fn main() {
let a = Foo { foo: 12i };
let b = Bar { bar: 12i };
println!("{} {}", a, b);
println!("{:?} {:?}", a, b);
}

View file

@ -9,5 +9,5 @@
// except according to those terms.
pub fn main() {
println!("{}", ("hi there!", "you"));
println!("{:?}", ("hi there!", "you"));
}

View file

@ -43,6 +43,6 @@ pub fn main()
"foo".to_string(),
"foo".to_string(), "foo".to_string(), "foo".to_string(),
"foo".to_string());
let v = format!("{}", u); // this is the line that causes the seg fault
let v = format!("{:?}", u); // this is the line that causes the seg fault
assert!(v.len() > 0);
}

View file

@ -24,6 +24,6 @@ pub fn main() {
let mut table = HashMap::new();
table.insert("one".to_string(), 1i);
table.insert("two".to_string(), 2i);
assert!(check_strs(table.to_string().as_slice(), "{one: 1, two: 2}") ||
check_strs(table.to_string().as_slice(), "{two: 2, one: 1}"));
assert!(check_strs(format!("{:?}", table).as_slice(), "HashMap {\"one\": 1i, \"two\": 2i}") ||
check_strs(format!("{:?}", table).as_slice(), "HashMap {\"two\": 2i, \"one\": 1i}"));
}

View file

@ -104,7 +104,7 @@ impl AsciiArt {
// Allows AsciiArt to be converted to a string using the libcore ToString trait.
// Note that the %s fmt! specifier will not call this automatically.
impl fmt::Show for AsciiArt {
impl fmt::String for AsciiArt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Convert each line into a string.
let lines = self.lines.iter()

View file

@ -19,7 +19,7 @@ struct S {
impl T for S {
fn print(&self) {
println!("{}", self);
println!("{:?}", self);
}
}

View file

@ -13,7 +13,7 @@
trait X {
fn call<T: std::fmt::Show>(&self, x: &T);
fn default_method<T: std::fmt::Show>(&self, x: &T) {
println!("X::default_method {}", x);
println!("X::default_method {:?}", x);
}
}
@ -27,7 +27,7 @@ struct Z<T> {
impl X for Y {
fn call<T: std::fmt::Show>(&self, x: &T) {
println!("X::call {} {}", self, x);
println!("X::call {:?} {:?}", self, x);
}
}

View file

@ -31,6 +31,6 @@ pub fn main() {
let sa = A { a: 100 };
let sb = B { b: 200, pa: &sa };
println!("sa is {}", sa);
println!("sb is {}", sb);
println!("sa is {:?}", sa);
println!("sb is {:?}", sb);
}

View file

@ -11,7 +11,7 @@
#![feature(slicing_syntax)]
fn assert_repr_eq<T: std::fmt::Show>(obj : T, expected : String) {
assert_eq!(expected, format!("{}", obj));
assert_eq!(expected, format!("{:?}", obj));
}
pub fn main() {
@ -20,7 +20,7 @@ pub fn main() {
let x = [(), ()];
let slice = x[0..1];
assert_repr_eq(abc[], "[1, 2, 3]".to_string());
assert_repr_eq(abc[], "[1i, 2i, 3i]".to_string());
assert_repr_eq(tf[], "[true, false]".to_string());
assert_repr_eq(x[], "[(), ()]".to_string());
assert_repr_eq(slice, "[()]".to_string());

View file

@ -15,19 +15,19 @@ enum foo {
}
fn check_log<T: std::fmt::Show>(exp: String, v: T) {
assert_eq!(exp, format!("{}", v));
assert_eq!(exp, format!("{:?}", v));
}
pub fn main() {
let mut x = Some(foo::a(22u));
let exp = "Some(a(22))".to_string();
let act = format!("{}", x);
let exp = "Some(a(22u))".to_string();
let act = format!("{:?}", x);
assert_eq!(act, exp);
check_log(exp, x);
x = None;
let exp = "None".to_string();
let act = format!("{}", x);
let act = format!("{:?}", x);
assert_eq!(act, exp);
check_log(exp, x);
}

View file

@ -21,7 +21,7 @@ enum bar {
}
pub fn main() {
assert_eq!("a(22)".to_string(), format!("{}", foo::a(22u)));
assert_eq!("c".to_string(), format!("{}", foo::c));
assert_eq!("d".to_string(), format!("{}", bar::d));
assert_eq!("a(22u)".to_string(), format!("{:?}", foo::a(22u)));
assert_eq!("c".to_string(), format!("{:?}", foo::c));
assert_eq!("d".to_string(), format!("{:?}", bar::d));
}

View file

@ -14,8 +14,8 @@ enum Numbers {
}
pub fn main() {
println!("{}", 1i);
println!("{}", 2.0f64);
println!("{}", Numbers::Three);
println!("{}", vec!(4i));
println!("{:?}", 1i);
println!("{:?}", 2.0f64);
println!("{:?}", Numbers::Three);
println!("{:?}", vec!(4i));
}

View file

@ -29,7 +29,7 @@ impl fmt::Show for Foo {
pub fn main() {
Thread::spawn(move|| {
let mut f = Foo(Cell::new(0));
println!("{}", f);
println!("{:?}", f);
let Foo(ref mut f) = f;
assert!(f.get() == 1);
}).join().ok().unwrap();

View file

@ -17,7 +17,7 @@ struct Thingy {
impl fmt::Show for Thingy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{ x: {}, y: {} }}", self.x, self.y)
write!(f, "{{ x: {:?}, y: {:?} }}", self.x, self.y)
}
}
@ -27,11 +27,11 @@ struct PolymorphicThingy<T> {
impl<T:fmt::Show> fmt::Show for PolymorphicThingy<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.x)
write!(f, "{:?}", self.x)
}
}
pub fn main() {
println!("{}", Thingy { x: 1, y: 2 }.to_string());
println!("{}", PolymorphicThingy { x: Thingy { x: 1, y: 2 } }.to_string());
println!("{:?}", Thingy { x: 1, y: 2 });
println!("{:?}", PolymorphicThingy { x: Thingy { x: 1, y: 2 } });
}

View file

@ -37,7 +37,7 @@ impl<K: PartialEq + std::fmt::Show, V:Clone> Index<K> for AssociationList<K,V> {
return &pair.value
}
}
panic!("No value found for key: {}", index);
panic!("No value found for key: {:?}", index);
}
}

View file

@ -53,11 +53,11 @@ pub fn main() {
let x = Outer {c8: 22u8, t: Inner {c64: 44u32}};
// Send it through the shape code
let y = format!("{}", x);
let y = format!("{:?}", x);
println!("align inner = {}", rusti::min_align_of::<Inner>());
println!("size outer = {}", mem::size_of::<Outer>());
println!("y = {}", y);
println!("align inner = {:?}", rusti::min_align_of::<Inner>());
println!("size outer = {:?}", mem::size_of::<Outer>());
println!("y = {:?}", y);
// per clang/gcc the alignment of `inner` is 4 on x86.
assert_eq!(rusti::min_align_of::<Inner>(), m::align());
@ -66,6 +66,6 @@ pub fn main() {
// because `inner`s alignment was 4.
assert_eq!(mem::size_of::<Outer>(), m::size());
assert_eq!(y, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());
assert_eq!(y, "Outer { c8: 22u8, t: Inner { c64: 44u32 } }".to_string());
}
}

View file

@ -82,11 +82,11 @@ pub fn main() {
unsafe {
let x = Outer {c8: 22u8, t: Inner {c64: 44u64}};
let y = format!("{}", x);
let y = format!("{:?}", x);
println!("align inner = {}", rusti::min_align_of::<Inner>());
println!("size outer = {}", mem::size_of::<Outer>());
println!("y = {}", y);
println!("align inner = {:?}", rusti::min_align_of::<Inner>());
println!("size outer = {:?}", mem::size_of::<Outer>());
println!("y = {:?}", y);
// per clang/gcc the alignment of `Inner` is 4 on x86.
assert_eq!(rusti::min_align_of::<Inner>(), m::m::align());
@ -95,6 +95,6 @@ pub fn main() {
// because `Inner`s alignment was 4.
assert_eq!(mem::size_of::<Outer>(), m::m::size());
assert_eq!(y, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());
assert_eq!(y, "Outer { c8: 22u8, t: Inner { c64: 44u64 } }".to_string());
}
}

View file

@ -37,7 +37,7 @@ pub fn main() {
let a = r(i);
let b = (a, 10i);
let (c, _d) = b;
println!("{}", c);
println!("{:?}", c);
}
assert_eq!(i.get(), 1);
}

View file

@ -57,7 +57,7 @@ fn start(argc: int, argv: *const *const u8) -> int {
fn pass(output: ProcessOutput) {
if !output.status.success() {
println!("{}", str::from_utf8(output.output.as_slice()));
println!("{}", str::from_utf8(output.error.as_slice()));
println!("{:?}", str::from_utf8(output.output.as_slice()));
println!("{:?}", str::from_utf8(output.error.as_slice()));
}
}

View file

@ -12,5 +12,5 @@
struct Foo(Box<[u8]>);
pub fn main() {
println!("{}", Foo(box [0, 1, 2]));
println!("{:?}", Foo(box [0, 1, 2]));
}

View file

@ -20,8 +20,8 @@ macro_rules! check {
static S: $t = $e;
let v: $t = $e;
assert_eq!(S, v);
assert_eq!(format!("{}", v).as_slice(), $s);
assert_eq!(format!("{}", S).as_slice(), $s);
assert_eq!(format!("{:?}", v).as_slice(), $s);
assert_eq!(format!("{:?}", S).as_slice(), $s);
});*
}}
}
@ -29,14 +29,14 @@ macro_rules! check {
pub fn main() {
check!(Option<u8>, 2,
None, "None",
Some(129u8), "Some(129)");
Some(129u8), "Some(129u8)");
check!(Option<i16>, 4,
None, "None",
Some(-20000i16), "Some(-20000)");
Some(-20000i16), "Some(-20000i16)");
check!(Either<u8, i8>, 2,
Either::Left(132u8), "Left(132)",
Either::Right(-32i8), "Right(-32)");
Either::Left(132u8), "Left(132u8)",
Either::Right(-32i8), "Right(-32i8)");
check!(Either<u8, i16>, 4,
Either::Left(132u8), "Left(132)",
Either::Right(-20000i16), "Right(-20000)");
Either::Left(132u8), "Left(132u8)",
Either::Right(-20000i16), "Right(-20000i16)");
}

View file

@ -12,208 +12,208 @@ extern crate libc;
pub fn main() {
let f = 1u as *const libc::FILE;
println!("{}", f as int);
println!("{}", f as uint);
println!("{}", f as i8);
println!("{}", f as i16);
println!("{}", f as i32);
println!("{}", f as i64);
println!("{}", f as u8);
println!("{}", f as u16);
println!("{}", f as u32);
println!("{}", f as u64);
println!("{:?}", f as int);
println!("{:?}", f as uint);
println!("{:?}", f as i8);
println!("{:?}", f as i16);
println!("{:?}", f as i32);
println!("{:?}", f as i64);
println!("{:?}", f as u8);
println!("{:?}", f as u16);
println!("{:?}", f as u32);
println!("{:?}", f as u64);
println!("{}", 1 as int);
println!("{}", 1 as uint);
println!("{}", 1 as *const libc::FILE);
println!("{}", 1 as i8);
println!("{}", 1 as i16);
println!("{}", 1 as i32);
println!("{}", 1 as i64);
println!("{}", 1 as u8);
println!("{}", 1 as u16);
println!("{}", 1 as u32);
println!("{}", 1 as u64);
println!("{}", 1i as f32);
println!("{}", 1i as f64);
println!("{:?}", 1 as int);
println!("{:?}", 1 as uint);
println!("{:?}", 1 as *const libc::FILE);
println!("{:?}", 1 as i8);
println!("{:?}", 1 as i16);
println!("{:?}", 1 as i32);
println!("{:?}", 1 as i64);
println!("{:?}", 1 as u8);
println!("{:?}", 1 as u16);
println!("{:?}", 1 as u32);
println!("{:?}", 1 as u64);
println!("{:?}", 1i as f32);
println!("{:?}", 1i as f64);
println!("{}", 1u as int);
println!("{}", 1u as uint);
println!("{}", 1u as *const libc::FILE);
println!("{}", 1u as i8);
println!("{}", 1u as i16);
println!("{}", 1u as i32);
println!("{}", 1u as i64);
println!("{}", 1u as u8);
println!("{}", 1u as u16);
println!("{}", 1u as u32);
println!("{}", 1u as u64);
println!("{}", 1u as f32);
println!("{}", 1u as f64);
println!("{:?}", 1u as int);
println!("{:?}", 1u as uint);
println!("{:?}", 1u as *const libc::FILE);
println!("{:?}", 1u as i8);
println!("{:?}", 1u as i16);
println!("{:?}", 1u as i32);
println!("{:?}", 1u as i64);
println!("{:?}", 1u as u8);
println!("{:?}", 1u as u16);
println!("{:?}", 1u as u32);
println!("{:?}", 1u as u64);
println!("{:?}", 1u as f32);
println!("{:?}", 1u as f64);
println!("{}", 1i8 as int);
println!("{}", 1i8 as uint);
println!("{}", 1i8 as *const libc::FILE);
println!("{}", 1i8 as i8);
println!("{}", 1i8 as i16);
println!("{}", 1i8 as i32);
println!("{}", 1i8 as i64);
println!("{}", 1i8 as u8);
println!("{}", 1i8 as u16);
println!("{}", 1i8 as u32);
println!("{}", 1i8 as u64);
println!("{}", 1i8 as f32);
println!("{}", 1i8 as f64);
println!("{:?}", 1i8 as int);
println!("{:?}", 1i8 as uint);
println!("{:?}", 1i8 as *const libc::FILE);
println!("{:?}", 1i8 as i8);
println!("{:?}", 1i8 as i16);
println!("{:?}", 1i8 as i32);
println!("{:?}", 1i8 as i64);
println!("{:?}", 1i8 as u8);
println!("{:?}", 1i8 as u16);
println!("{:?}", 1i8 as u32);
println!("{:?}", 1i8 as u64);
println!("{:?}", 1i8 as f32);
println!("{:?}", 1i8 as f64);
println!("{}", 1u8 as int);
println!("{}", 1u8 as uint);
println!("{}", 1u8 as *const libc::FILE);
println!("{}", 1u8 as i8);
println!("{}", 1u8 as i16);
println!("{}", 1u8 as i32);
println!("{}", 1u8 as i64);
println!("{}", 1u8 as u8);
println!("{}", 1u8 as u16);
println!("{}", 1u8 as u32);
println!("{}", 1u8 as u64);
println!("{}", 1u8 as f32);
println!("{}", 1u8 as f64);
println!("{:?}", 1u8 as int);
println!("{:?}", 1u8 as uint);
println!("{:?}", 1u8 as *const libc::FILE);
println!("{:?}", 1u8 as i8);
println!("{:?}", 1u8 as i16);
println!("{:?}", 1u8 as i32);
println!("{:?}", 1u8 as i64);
println!("{:?}", 1u8 as u8);
println!("{:?}", 1u8 as u16);
println!("{:?}", 1u8 as u32);
println!("{:?}", 1u8 as u64);
println!("{:?}", 1u8 as f32);
println!("{:?}", 1u8 as f64);
println!("{}", 1i16 as int);
println!("{}", 1i16 as uint);
println!("{}", 1i16 as *const libc::FILE);
println!("{}", 1i16 as i8);
println!("{}", 1i16 as i16);
println!("{}", 1i16 as i32);
println!("{}", 1i16 as i64);
println!("{}", 1i16 as u8);
println!("{}", 1i16 as u16);
println!("{}", 1i16 as u32);
println!("{}", 1i16 as u64);
println!("{}", 1i16 as f32);
println!("{}", 1i16 as f64);
println!("{:?}", 1i16 as int);
println!("{:?}", 1i16 as uint);
println!("{:?}", 1i16 as *const libc::FILE);
println!("{:?}", 1i16 as i8);
println!("{:?}", 1i16 as i16);
println!("{:?}", 1i16 as i32);
println!("{:?}", 1i16 as i64);
println!("{:?}", 1i16 as u8);
println!("{:?}", 1i16 as u16);
println!("{:?}", 1i16 as u32);
println!("{:?}", 1i16 as u64);
println!("{:?}", 1i16 as f32);
println!("{:?}", 1i16 as f64);
println!("{}", 1u16 as int);
println!("{}", 1u16 as uint);
println!("{}", 1u16 as *const libc::FILE);
println!("{}", 1u16 as i8);
println!("{}", 1u16 as i16);
println!("{}", 1u16 as i32);
println!("{}", 1u16 as i64);
println!("{}", 1u16 as u8);
println!("{}", 1u16 as u16);
println!("{}", 1u16 as u32);
println!("{}", 1u16 as u64);
println!("{}", 1u16 as f32);
println!("{}", 1u16 as f64);
println!("{:?}", 1u16 as int);
println!("{:?}", 1u16 as uint);
println!("{:?}", 1u16 as *const libc::FILE);
println!("{:?}", 1u16 as i8);
println!("{:?}", 1u16 as i16);
println!("{:?}", 1u16 as i32);
println!("{:?}", 1u16 as i64);
println!("{:?}", 1u16 as u8);
println!("{:?}", 1u16 as u16);
println!("{:?}", 1u16 as u32);
println!("{:?}", 1u16 as u64);
println!("{:?}", 1u16 as f32);
println!("{:?}", 1u16 as f64);
println!("{}", 1i32 as int);
println!("{}", 1i32 as uint);
println!("{}", 1i32 as *const libc::FILE);
println!("{}", 1i32 as i8);
println!("{}", 1i32 as i16);
println!("{}", 1i32 as i32);
println!("{}", 1i32 as i64);
println!("{}", 1i32 as u8);
println!("{}", 1i32 as u16);
println!("{}", 1i32 as u32);
println!("{}", 1i32 as u64);
println!("{}", 1i32 as f32);
println!("{}", 1i32 as f64);
println!("{:?}", 1i32 as int);
println!("{:?}", 1i32 as uint);
println!("{:?}", 1i32 as *const libc::FILE);
println!("{:?}", 1i32 as i8);
println!("{:?}", 1i32 as i16);
println!("{:?}", 1i32 as i32);
println!("{:?}", 1i32 as i64);
println!("{:?}", 1i32 as u8);
println!("{:?}", 1i32 as u16);
println!("{:?}", 1i32 as u32);
println!("{:?}", 1i32 as u64);
println!("{:?}", 1i32 as f32);
println!("{:?}", 1i32 as f64);
println!("{}", 1u32 as int);
println!("{}", 1u32 as uint);
println!("{}", 1u32 as *const libc::FILE);
println!("{}", 1u32 as i8);
println!("{}", 1u32 as i16);
println!("{}", 1u32 as i32);
println!("{}", 1u32 as i64);
println!("{}", 1u32 as u8);
println!("{}", 1u32 as u16);
println!("{}", 1u32 as u32);
println!("{}", 1u32 as u64);
println!("{}", 1u32 as f32);
println!("{}", 1u32 as f64);
println!("{:?}", 1u32 as int);
println!("{:?}", 1u32 as uint);
println!("{:?}", 1u32 as *const libc::FILE);
println!("{:?}", 1u32 as i8);
println!("{:?}", 1u32 as i16);
println!("{:?}", 1u32 as i32);
println!("{:?}", 1u32 as i64);
println!("{:?}", 1u32 as u8);
println!("{:?}", 1u32 as u16);
println!("{:?}", 1u32 as u32);
println!("{:?}", 1u32 as u64);
println!("{:?}", 1u32 as f32);
println!("{:?}", 1u32 as f64);
println!("{}", 1i64 as int);
println!("{}", 1i64 as uint);
println!("{}", 1i64 as *const libc::FILE);
println!("{}", 1i64 as i8);
println!("{}", 1i64 as i16);
println!("{}", 1i64 as i32);
println!("{}", 1i64 as i64);
println!("{}", 1i64 as u8);
println!("{}", 1i64 as u16);
println!("{}", 1i64 as u32);
println!("{}", 1i64 as u64);
println!("{}", 1i64 as f32);
println!("{}", 1i64 as f64);
println!("{:?}", 1i64 as int);
println!("{:?}", 1i64 as uint);
println!("{:?}", 1i64 as *const libc::FILE);
println!("{:?}", 1i64 as i8);
println!("{:?}", 1i64 as i16);
println!("{:?}", 1i64 as i32);
println!("{:?}", 1i64 as i64);
println!("{:?}", 1i64 as u8);
println!("{:?}", 1i64 as u16);
println!("{:?}", 1i64 as u32);
println!("{:?}", 1i64 as u64);
println!("{:?}", 1i64 as f32);
println!("{:?}", 1i64 as f64);
println!("{}", 1u64 as int);
println!("{}", 1u64 as uint);
println!("{}", 1u64 as *const libc::FILE);
println!("{}", 1u64 as i8);
println!("{}", 1u64 as i16);
println!("{}", 1u64 as i32);
println!("{}", 1u64 as i64);
println!("{}", 1u64 as u8);
println!("{}", 1u64 as u16);
println!("{}", 1u64 as u32);
println!("{}", 1u64 as u64);
println!("{}", 1u64 as f32);
println!("{}", 1u64 as f64);
println!("{:?}", 1u64 as int);
println!("{:?}", 1u64 as uint);
println!("{:?}", 1u64 as *const libc::FILE);
println!("{:?}", 1u64 as i8);
println!("{:?}", 1u64 as i16);
println!("{:?}", 1u64 as i32);
println!("{:?}", 1u64 as i64);
println!("{:?}", 1u64 as u8);
println!("{:?}", 1u64 as u16);
println!("{:?}", 1u64 as u32);
println!("{:?}", 1u64 as u64);
println!("{:?}", 1u64 as f32);
println!("{:?}", 1u64 as f64);
println!("{}", 1u64 as int);
println!("{}", 1u64 as uint);
println!("{}", 1u64 as *const libc::FILE);
println!("{}", 1u64 as i8);
println!("{}", 1u64 as i16);
println!("{}", 1u64 as i32);
println!("{}", 1u64 as i64);
println!("{}", 1u64 as u8);
println!("{}", 1u64 as u16);
println!("{}", 1u64 as u32);
println!("{}", 1u64 as u64);
println!("{}", 1u64 as f32);
println!("{}", 1u64 as f64);
println!("{:?}", 1u64 as int);
println!("{:?}", 1u64 as uint);
println!("{:?}", 1u64 as *const libc::FILE);
println!("{:?}", 1u64 as i8);
println!("{:?}", 1u64 as i16);
println!("{:?}", 1u64 as i32);
println!("{:?}", 1u64 as i64);
println!("{:?}", 1u64 as u8);
println!("{:?}", 1u64 as u16);
println!("{:?}", 1u64 as u32);
println!("{:?}", 1u64 as u64);
println!("{:?}", 1u64 as f32);
println!("{:?}", 1u64 as f64);
println!("{}", true as int);
println!("{}", true as uint);
println!("{}", true as *const libc::FILE);
println!("{}", true as i8);
println!("{}", true as i16);
println!("{}", true as i32);
println!("{}", true as i64);
println!("{}", true as u8);
println!("{}", true as u16);
println!("{}", true as u32);
println!("{}", true as u64);
println!("{}", true as f32);
println!("{}", true as f64);
println!("{:?}", true as int);
println!("{:?}", true as uint);
println!("{:?}", true as *const libc::FILE);
println!("{:?}", true as i8);
println!("{:?}", true as i16);
println!("{:?}", true as i32);
println!("{:?}", true as i64);
println!("{:?}", true as u8);
println!("{:?}", true as u16);
println!("{:?}", true as u32);
println!("{:?}", true as u64);
println!("{:?}", true as f32);
println!("{:?}", true as f64);
println!("{}", 1f32 as int);
println!("{}", 1f32 as uint);
println!("{}", 1f32 as i8);
println!("{}", 1f32 as i16);
println!("{}", 1f32 as i32);
println!("{}", 1f32 as i64);
println!("{}", 1f32 as u8);
println!("{}", 1f32 as u16);
println!("{}", 1f32 as u32);
println!("{}", 1f32 as u64);
println!("{}", 1f32 as f32);
println!("{}", 1f32 as f64);
println!("{:?}", 1f32 as int);
println!("{:?}", 1f32 as uint);
println!("{:?}", 1f32 as i8);
println!("{:?}", 1f32 as i16);
println!("{:?}", 1f32 as i32);
println!("{:?}", 1f32 as i64);
println!("{:?}", 1f32 as u8);
println!("{:?}", 1f32 as u16);
println!("{:?}", 1f32 as u32);
println!("{:?}", 1f32 as u64);
println!("{:?}", 1f32 as f32);
println!("{:?}", 1f32 as f64);
println!("{}", 1f64 as int);
println!("{}", 1f64 as uint);
println!("{}", 1f64 as i8);
println!("{}", 1f64 as i16);
println!("{}", 1f64 as i32);
println!("{}", 1f64 as i64);
println!("{}", 1f64 as u8);
println!("{}", 1f64 as u16);
println!("{}", 1f64 as u32);
println!("{}", 1f64 as u64);
println!("{}", 1f64 as f32);
println!("{}", 1f64 as f64);
println!("{:?}", 1f64 as int);
println!("{:?}", 1f64 as uint);
println!("{:?}", 1f64 as i8);
println!("{:?}", 1f64 as i16);
println!("{:?}", 1f64 as i32);
println!("{:?}", 1f64 as i64);
println!("{:?}", 1f64 as u8);
println!("{:?}", 1f64 as u16);
println!("{:?}", 1f64 as u32);
println!("{:?}", 1f64 as u64);
println!("{:?}", 1f64 as f32);
println!("{:?}", 1f64 as f64);
}

View file

@ -21,7 +21,7 @@ struct t_rec {
pub fn main() {
let x = t_rec {c8: 22u8, t: a_tag::a_tag_var(44u64)};
let y = format!("{}", x);
println!("y = {}", y);
assert_eq!(y, "t_rec { c8: 22, t: a_tag_var(44) }".to_string());
let y = format!("{:?}", x);
println!("y = {:?}", y);
assert_eq!(y, "t_rec { c8: 22u8, t: a_tag_var(44u64) }".to_string());
}

View file

@ -18,9 +18,9 @@ enum color {
}
pub fn main() {
let act = format!("{}", color::red);
let act = format!("{:?}", color::red);
println!("{}", act);
assert_eq!("red".to_string(), act);
assert_eq!("green".to_string(), format!("{}", color::green));
assert_eq!("white".to_string(), format!("{}", color::white));
assert_eq!("green".to_string(), format!("{:?}", color::green));
assert_eq!("white".to_string(), format!("{:?}", color::white));
}

View file

@ -19,5 +19,5 @@ pub fn main() {
let (tx, rx) = channel();
tx.send(42i);
let r = rx.recv();
println!("{}", r);
println!("{:?}", r);
}

View file

@ -13,5 +13,5 @@ struct Foo(int, int);
pub fn main() {
let x = Foo(1, 2);
println!("{}", x);
println!("{:?}", x);
}

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!((vec!(0i, 1)).to_string(), "0, 1".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!(foo.to_string(), "3, 4".to_string());
assert_eq!(bar.to_string(), "4, 5".to_string());
}