auto merge of #12066 : huonw/rust/show2, r=alexcrichton

- Convert the formatting traits to `&self` rather than `_: &Self`
- Rejig `syntax::ext::{format,deriving}` a little in preparation
- Implement `#[deriving(Show)]`
This commit is contained in:
bors 2014-02-07 20:46:30 -08:00
commit dde2e0b386
41 changed files with 627 additions and 339 deletions

View file

@ -0,0 +1,26 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
extern mod extra;
struct Error;
#[deriving(Show)]
enum Enum {
A {
x: Error //~ ERROR
}
}
fn main() {}

View file

@ -0,0 +1,26 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
extern mod extra;
struct Error;
#[deriving(Show)]
enum Enum {
A(
Error //~ ERROR
)
}
fn main() {}

View file

@ -0,0 +1,24 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
extern mod extra;
struct Error;
#[deriving(Show)]
struct Struct {
x: Error //~ ERROR
}
fn main() {}

View file

@ -0,0 +1,24 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
#[feature(struct_variant)];
extern mod extra;
struct Error;
#[deriving(Show)]
struct Struct(
Error //~ ERROR
);
fn main() {}

View file

@ -0,0 +1,42 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[feature(struct_variant, macro_rules)];
#[deriving(Show)]
struct Unit;
#[deriving(Show)]
struct Tuple(int, uint);
#[deriving(Show)]
struct Struct { x: int, y: uint }
#[deriving(Show)]
enum Enum {
Nullary,
Variant(int, uint),
StructVariant { x: int, y : uint }
}
macro_rules! t {
($x:expr, $expected:expr) => {
assert_eq!(format!("{}", $x), $expected.to_owned())
}
}
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!(Nullary, "Nullary");
t!(Variant(1, 2), "Variant(1, 2)");
t!(StructVariant { x: 1, y: 2 }, "StructVariant { x: 1, y: 2 }");
}

View file

@ -23,12 +23,12 @@ struct A;
struct B;
impl fmt::Signed for A {
fn fmt(_: &A, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.buf.write("aloha".as_bytes())
}
}
impl fmt::Signed for B {
fn fmt(_: &B, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.buf.write("adios".as_bytes())
}
}

View file

@ -17,8 +17,8 @@ use std::fmt;
struct Foo(Cell<int>);
impl fmt::Show for Foo {
fn fmt(f: &Foo, _fmt: &mut fmt::Formatter) -> fmt::Result {
let Foo(ref f) = *f;
fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result {
let Foo(ref f) = *self;
assert!(f.get() == 0);
f.set(1);
Ok(())