Update docs and tests for #[deriving(Show)].
This commit is contained in:
parent
6a8b3ae22f
commit
b89afe2af7
7 changed files with 106 additions and 4 deletions
|
@ -1969,13 +1969,14 @@ impl<T: Eq> Eq for Foo<T> {
|
|||
Supported traits for `deriving` are:
|
||||
|
||||
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
|
||||
* Serialization: `Encodable`, `Decodable`. These require `extra`.
|
||||
* Serialization: `Encodable`, `Decodable`. These require `serialize`.
|
||||
* `Clone` and `DeepClone`, to perform (deep) copies.
|
||||
* `IterBytes`, to iterate over the bytes in a data type.
|
||||
* `Rand`, to create a random instance of a data type.
|
||||
* `Default`, to create an empty instance of a data type.
|
||||
* `Zero`, to create an zero instance of a numeric data type.
|
||||
* `FromPrimitive`, to create an instance from a numeric primitve.
|
||||
* `FromPrimitive`, to create an instance from a numeric primitive.
|
||||
* `Show`, to format a value using the `{}` formatter.
|
||||
|
||||
### Stability
|
||||
One can indicate the stability of an API using the following attributes:
|
||||
|
|
|
@ -2523,7 +2523,7 @@ enum ABC { A, B, C }
|
|||
|
||||
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
|
||||
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `DeepClone`,
|
||||
`IterBytes`, `Rand`, `Default`, `Zero`, and `ToStr`.
|
||||
`IterBytes`, `Rand`, `Default`, `Zero`, `FromPrimitive` and `Show`.
|
||||
|
||||
# Crates and the module system
|
||||
|
||||
|
|
|
@ -118,7 +118,8 @@ traits = {
|
|||
for (trait, supers, errs) in [('Rand', [], 1),
|
||||
('Clone', [], 1), ('DeepClone', ['Clone'], 1),
|
||||
('Eq', [], 2), ('Ord', [], 8),
|
||||
('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1)]:
|
||||
('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1),
|
||||
('Show', [], 1)]:
|
||||
traits[trait] = (ALL, supers, errs)
|
||||
|
||||
for (trait, (types, super_traits, error_count)) in traits.items():
|
||||
|
|
|
@ -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() {}
|
26
src/test/compile-fail/deriving-span-Show-enum.rs
Normal file
26
src/test/compile-fail/deriving-span-Show-enum.rs
Normal 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() {}
|
24
src/test/compile-fail/deriving-span-Show-struct.rs
Normal file
24
src/test/compile-fail/deriving-span-Show-struct.rs
Normal 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() {}
|
24
src/test/compile-fail/deriving-span-Show-tuple-struct.rs
Normal file
24
src/test/compile-fail/deriving-span-Show-tuple-struct.rs
Normal 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() {}
|
Loading…
Add table
Reference in a new issue