Skip to content

Commit 511ba70

Browse files
committed
---
yaml --- r: 140748 b: refs/heads/try2 c: d43908a h: refs/heads/master v: v3
1 parent f902b6b commit 511ba70

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 8d4a3d58b7e06edf223f6cc51b9c61fcf6b49832
8+
refs/heads/try2: d43908a3a7b2889b847306070593f58b93ca1a6b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,8 @@ names are effectively reserved. Some significant attributes include:
14251425
* The `test` attribute, for marking functions as unit tests.
14261426
* The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint checks. Lint checks supported
14271427
by the compiler can be found via `rustc -W help`.
1428+
* The `deriving` attribute, for automatically generating
1429+
implementations of certain traits.
14281430

14291431
Other attributes may be added or removed during development of the language.
14301432

@@ -1526,6 +1528,47 @@ A complete list of the built-in language items follows:
15261528
> **Note:** This list is likely to become out of date. We should auto-generate it
15271529
> from `librustc/middle/lang_items.rs`.
15281530
1531+
### Deriving
1532+
1533+
The `deriving` attribute allows certain traits to be automatically
1534+
implemented for data structures. For example, the following will
1535+
create an `impl` for the `Eq` and `Clone` traits for `Foo`, the type
1536+
parameter `T` will be given the `Eq` or `Clone` constraints for the
1537+
appropriate `impl`:
1538+
1539+
~~~
1540+
#[deriving(Eq, Clone)]
1541+
struct Foo<T> {
1542+
a: int,
1543+
b: T
1544+
}
1545+
~~~
1546+
1547+
The generated `impl` for `Eq` is equivalent to
1548+
1549+
~~~
1550+
# struct Foo<T> { a: int, b: T }
1551+
impl<T: Eq> Eq for Foo<T> {
1552+
fn eq(&self, other: &Foo<T>) -> bool {
1553+
self.a == other.a && self.b == other.b
1554+
}
1555+
1556+
fn ne(&self, other: &Foo<T>) -> bool {
1557+
self.a != other.a || self.b != other.b
1558+
}
1559+
}
1560+
~~~
1561+
1562+
Supported traits for `deriving` are:
1563+
1564+
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
1565+
* Serialization: `Encodable`, `Decodable`. These require `std`.
1566+
* `Clone`, to perform deep copies.
1567+
* `IterBytes`, to iterate over the bytes in a data type.
1568+
* `Rand`, to create a random instance of a data type.
1569+
* `ToStr`, to convert to a string. For a type with this instance,
1570+
`obj.to_str()` has the same output as `fmt!("%?", obj)`.
1571+
15291572
# Statements and expressions
15301573

15311574
Rust is _primarily_ an expression language. This means that most forms of

branches/try2/doc/tutorial.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,27 @@ let nonsense = mycircle.radius() * mycircle.area();
22902290

22912291
> ***Note:*** Trait inheritance does not actually work with objects yet
22922292
2293+
## Deriving implementations for traits
2294+
2295+
A small number of traits in `core` and `std` can have implementations
2296+
that can be automatically derived. These instances are specified by
2297+
placing the `deriving` attribute on a data type declaration. For
2298+
example, the following will mean that `Circle` has an implementation
2299+
for `Eq` and can be used with the equality operators, and that a value
2300+
of type `ABC` can be randomly generated and converted to a string:
2301+
2302+
~~~
2303+
#[deriving(Eq)]
2304+
struct Circle { radius: float }
2305+
2306+
#[deriving(Rand, ToStr)]
2307+
enum ABC { A, B, C }
2308+
~~~
2309+
2310+
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2311+
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `IterBytes`, `Rand` and
2312+
`ToStr`.
2313+
22932314
# Modules and crates
22942315

22952316
The Rust namespace is arranged in a hierarchy of modules. Each source

branches/try2/src/librustc/middle/trans/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ fn padding(size: u64) -> ValueRef {
574574
}
575575

576576
// XXX this utility routine should be somewhere more general
577-
#[inline(always)]
577+
#[always_inline]
578578
fn roundup(x: u64, a: u64) -> u64 { ((x + (a - 1)) / a) * a }
579579

580580
/// Get the discriminant of a constant value. (Not currently used.)

branches/try2/src/rt/rust_globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#endif
2121

2222
#if defined(__GNUC__)
23-
#define ALWAYS_INLINE __attribute__((always_inline)) INLINE
23+
#define ALWAYS_INLINE __attribute((always_inline)) INLINE
2424
#elif defined(_MSC_VER)
2525
#define ALWAYS_INLINE __forceinline
2626
#else

0 commit comments

Comments
 (0)