Skip to content

Commit 5515fd5

Browse files
committed
Merge remote-tracking branch 'remotes/origin/incoming' into incoming
2 parents aa3505d + 2304fe6 commit 5515fd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+519
-592
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You're not off the hook even if you just stick to documentation; code examples i
1111
Pull requests will be treated as "review requests",
1212
and we will give feedback we expect to see corrected on [style](https://github.com/mozilla/rust/wiki/Note-style-guide) and substance before pulling.
1313
Changes contributed via pull request should focus on a single issue at a time, like any other.
14-
We will not look accept pull-requests that try to "sneak" unrelated changes in.
14+
We will not accept pull-requests that try to "sneak" unrelated changes in.
1515

1616
Normally, all pull requests must include regression tests (see [Note-testsuite](https://github.com/mozilla/rust/wiki/Note-testsuite)) that test your change.
1717
Occasionally, a change will be very difficult to test for.

doc/rust.md

+43-99
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ function defined above on `[1, 2]` will instantiate type parameter `T`
908908
with `int`, and require the closure parameter to have type
909909
`fn(int)`.
910910

911+
The type parameters can also be explicitly supplied in a trailing
912+
[path](#paths) component after the function name. This might be necessary
913+
if there is not sufficient context to determine the type parameters. For
914+
example, `sys::size_of::<u32>() == 4`.
915+
911916
Since a parameter type is opaque to the generic function, the set of
912917
operations that can be performed on it is limited. Values of parameter
913918
type can always be moved, but they can only be copied when the
@@ -1085,6 +1090,15 @@ let p = Point(10, 11);
10851090
let px: int = match p { Point(x, _) => x };
10861091
~~~~
10871092

1093+
A _unit-like struct_ is a structure without any fields, defined by leaving off the fields list entirely.
1094+
Such types will have a single value, just like the [unit value `()`](#unit-and-boolean-literals) of the unit type.
1095+
For example:
1096+
1097+
~~~~
1098+
struct Cookie;
1099+
let c = [Cookie, Cookie, Cookie, Cookie];
1100+
~~~~
1101+
10881102
### Enumerations
10891103

10901104
An _enumeration_ is a simultaneous definition of a nominal [enumerated type](#enumerated-types) as well as a set of *constructors*,
@@ -1285,19 +1299,22 @@ An _implementation_ is an item that implements a [trait](#traits) for a specific
12851299
Implementations are defined with the keyword `impl`.
12861300

12871301
~~~~
1288-
# type Point = {x: float, y: float};
1302+
# struct Point {x: float, y: float};
12891303
# type Surface = int;
1290-
# type BoundingBox = {x: float, y: float, width: float, height: float};
1304+
# struct BoundingBox {x: float, y: float, width: float, height: float};
12911305
# trait Shape { fn draw(Surface); fn bounding_box() -> BoundingBox; }
12921306
# fn do_draw_circle(s: Surface, c: Circle) { }
12931307
1294-
type Circle = {radius: float, center: Point};
1308+
struct Circle {
1309+
radius: float,
1310+
center: Point,
1311+
}
12951312
12961313
impl Shape for Circle {
12971314
fn draw(s: Surface) { do_draw_circle(s, self); }
12981315
fn bounding_box() -> BoundingBox {
12991316
let r = self.radius;
1300-
{x: self.center.x - r, y: self.center.y - r,
1317+
BoundingBox{x: self.center.x - r, y: self.center.y - r,
13011318
width: 2.0 * r, height: 2.0 * r}
13021319
}
13031320
}
@@ -1590,7 +1607,8 @@ struct_expr : expr_path '{' ident ':' expr
15901607
[ ',' ident ':' expr ] *
15911608
[ ".." expr ] '}' |
15921609
expr_path '(' expr
1593-
[ ',' expr ] * ')'
1610+
[ ',' expr ] * ')' |
1611+
expr_path
15941612
~~~~~~~~
15951613

15961614
There are several forms of structure expressions.
@@ -1600,23 +1618,28 @@ providing the field values of a new instance of the structure.
16001618
A field name can be any identifier, and is separated from its value expression by a colon.
16011619
To indicate that a field is mutable, the `mut` keyword is written before its name.
16021620

1603-
A _tuple structure expression_ constists of the [path](#paths) of a [structure item](#structures),
1621+
A _tuple structure expression_ consists of the [path](#paths) of a [structure item](#structures),
16041622
followed by a parenthesized list of one or more comma-separated expressions
16051623
(in other words, the path of a structured item followed by a tuple expression).
16061624
The structure item must be a tuple structure item.
16071625

1626+
A _unit-like structure expression_ consists only of the [path](#paths) of a [structure item](#structures).
1627+
16081628
The following are examples of structure expressions:
16091629

16101630
~~~~
16111631
# struct Point { x: float, y: float }
16121632
# struct TuplePoint(float, float);
16131633
# mod game { pub struct User { name: &str, age: uint, score: uint } }
1634+
# struct Cookie; fn some_fn<T>(t: T) {}
16141635
Point {x: 10f, y: 20f};
16151636
TuplePoint(10f, 20f);
16161637
let u = game::User {name: "Joe", age: 35u, score: 100_000};
1638+
some_fn::<Cookie>(Cookie);
16171639
~~~~
16181640

16191641
A structure expression forms a new value of the named structure type.
1642+
Note that for a given *unit-like* structure type, this will always be the same value.
16201643

16211644
A structure expression can terminate with the syntax `..` followed by an expression to denote a functional update.
16221645
The expression following `..` (the base) must be of the same structure type as the new structure type being formed.
@@ -1637,38 +1660,6 @@ rec_expr : '{' ident ':' expr
16371660
[ ".." expr ] '}'
16381661
~~~~~~~~
16391662

1640-
> **Note:** In future versions of Rust, record expressions and [record types](#record-types) will be removed.
1641-
1642-
A [_record_](#record-types) _expression_ is one or more comma-separated
1643-
name-value pairs enclosed by braces. A fieldname can be any identifier,
1644-
and is separated from its value expression by a
1645-
colon. To indicate that a field is mutable, the `mut` keyword is
1646-
written before its name.
1647-
1648-
~~~~
1649-
{x: 10f, y: 20f};
1650-
{name: "Joe", age: 35u, score: 100_000};
1651-
{ident: "X", mut count: 0u};
1652-
~~~~
1653-
1654-
The order of the fields in a record expression is significant, and
1655-
determines the type of the resulting value. `{a: u8, b: u8}` and `{b:
1656-
u8, a: u8}` are two different fields.
1657-
1658-
A record expression can terminate with the syntax `..` followed by an
1659-
expression to denote a functional update. The expression following
1660-
`..` (the base) must be of a record type that includes at least all the
1661-
fields mentioned in the record expression. A new record will be
1662-
created, of the same type as the base expression, with the given
1663-
values for the fields that were explicitly specified, and the values
1664-
in the base record for all other fields. The ordering of the fields in
1665-
such a record expression is not significant.
1666-
1667-
~~~~
1668-
let base = {x: 1, y: 2, z: 3};
1669-
{y: 0, z: 10, .. base};
1670-
~~~~
1671-
16721663
### Method-call expressions
16731664

16741665
~~~~~~~~{.ebnf .gram}
@@ -1689,7 +1680,7 @@ field_expr : expr '.' ident
16891680

16901681
A _field expression_ consists of an expression followed by a single dot and an identifier,
16911682
when not immediately followed by a parenthesized expression-list (the latter is a [method call expression](#method-call-expressions)).
1692-
A field expression denotes a field of a [structure](#structure-types) or [record](#record-types).
1683+
A field expression denotes a field of a [structure](#structure-types).
16931684

16941685
~~~~~~~~ {.field}
16951686
myrecord.myfield;
@@ -1905,8 +1896,10 @@ An example of three different swap expressions:
19051896
# let mut x = &mut [0];
19061897
# let mut a = &mut [0];
19071898
# let i = 0;
1908-
# let y = {mut z: 0};
1909-
# let b = {mut c: 0};
1899+
# struct S1 { z: int };
1900+
# struct S2 { c: int };
1901+
# let mut y = S1{z: 0};
1902+
# let mut b = S2{c: 0};
19101903
19111904
x <-> a;
19121905
x[i] <-> a[i];
@@ -2040,12 +2033,14 @@ an optional reference slot to serve as the function's output, bound to the
20402033
`lval` on the right hand side of the call. If the function eventually returns,
20412034
then the expression completes.
20422035

2043-
An example of a call expression:
2036+
Some examples of call expressions:
20442037

20452038
~~~~
20462039
# fn add(x: int, y: int) -> int { 0 }
2040+
# use core::from_str::FromStr::from_str;
20472041
20482042
let x: int = add(1, 2);
2043+
let pi = from_str::<f32>("3.14");
20492044
~~~~
20502045

20512046
### Lambda expressions
@@ -2328,42 +2323,6 @@ match x {
23282323
}
23292324
~~~~
23302325

2331-
Records and structures can also be pattern-matched and their fields bound to variables.
2332-
When matching fields of a record,
2333-
the fields being matched are specified first,
2334-
then a placeholder (`_`) represents the remaining fields.
2335-
2336-
~~~~
2337-
# type options = {choose: bool, size: ~str};
2338-
# type player = {player: ~str, stats: (), options: options};
2339-
# fn load_stats() { }
2340-
# fn choose_player(r: &player) { }
2341-
# fn next_player() { }
2342-
2343-
fn main() {
2344-
let r = {
2345-
player: ~"ralph",
2346-
stats: load_stats(),
2347-
options: {
2348-
choose: true,
2349-
size: ~"small"
2350-
}
2351-
};
2352-
2353-
match r {
2354-
{options: {choose: true, _}, _} => {
2355-
choose_player(&r)
2356-
}
2357-
{player: ref p, options: {size: ~"small", _}, _} => {
2358-
log(info, (copy *p) + ~" is small");
2359-
}
2360-
_ => {
2361-
next_player();
2362-
}
2363-
}
2364-
}
2365-
~~~~
2366-
23672326
Patterns that bind variables default to binding to a copy of the matched value. This can be made
23682327
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
23692328
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
@@ -2643,7 +2602,10 @@ the resulting `struct` value will always be laid out in memory in the order spec
26432602
The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
26442603
to restrict access to implementation-private data in a structure.
26452604

2646-
A `tuple struct` type is just like a structure type, except that the fields are anonymous.
2605+
A _tuple struct_ type is just like a structure type, except that the fields are anonymous.
2606+
2607+
A _unit-like struct_ type is like a structure type, except that it has no fields.
2608+
The one value constructed by the associated [structure expression](#structure-expression) is the only value that inhabits such a type.
26472609

26482610
### Enumerated types
26492611

@@ -2692,25 +2654,6 @@ let a: List<int> = Cons(7, @Cons(13, @Nil));
26922654
~~~~
26932655

26942656

2695-
### Record types
2696-
2697-
> **Note:** Records are not nominal types, thus do not directly support recursion, visibility control,
2698-
> out-of-order field initialization, or coherent trait implementation.
2699-
> Records are therefore deprecated and will be removed in future versions of Rust.
2700-
> [Structure types](#structure-types) should be used instead.
2701-
2702-
The record type-constructor forms a new heterogeneous product of values.
2703-
Fields of a record type are accessed by name and are arranged in memory in the order specified by the record type.
2704-
2705-
An example of a record type and its use:
2706-
2707-
~~~~
2708-
type Point = {x: int, y: int};
2709-
let p: Point = {x: 10, y: 11};
2710-
let px: int = p.x;
2711-
~~~~
2712-
2713-
27142657
### Pointer types
27152658

27162659
All pointers in Rust are explicit first-class values.
@@ -3040,7 +2983,8 @@ Some operations (such as field selection) implicitly dereference boxes. An
30402983
example of an _implicit dereference_ operation performed on box values:
30412984

30422985
~~~~~~~~
3043-
let x = @{y: 10};
2986+
struct Foo { y: int }
2987+
let x = @Foo{y: 10};
30442988
assert x.y == 10;
30452989
~~~~~~~~
30462990

doc/tutorial-borrowed-ptr.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ operator. For example, I could write:
166166
# struct Point {x: float, y: float} // as before
167167
# struct Size {w: float, h: float} // as before
168168
# struct Rectangle {origin: Point, size: Size}
169-
# let rect_stack = &{origin: Point {x: 1f, y: 2f}, size: Size {w: 3f, h: 4f}};
170-
# let rect_managed = @{origin: Point {x: 3f, y: 4f}, size: Size {w: 3f, h: 4f}};
171-
# let rect_unique = ~{origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}};
169+
# let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, size: Size {w: 3f, h: 4f}};
170+
# let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, size: Size {w: 3f, h: 4f}};
171+
# let rect_unique = ~Rectangle {origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}};
172172
# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f }
173173
compute_distance(&rect_stack.origin, &rect_managed.origin);
174174
~~~
@@ -274,13 +274,14 @@ the following function is legal:
274274

275275
~~~
276276
# fn some_condition() -> bool { true }
277+
# struct Foo { f: int }
277278
fn example3() -> int {
278-
let mut x = ~{f: 3};
279+
let mut x = ~Foo {f: 3};
279280
if some_condition() {
280281
let y = &x.f; // -+ L
281282
return *y; // |
282283
} // -+
283-
x = ~{f: 4};
284+
x = ~Foo {f: 4};
284285
...
285286
# return 0;
286287
}

src/libcore/at_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub mod raw {
183183
use at_vec::{capacity, rustrt};
184184
use cast::transmute;
185185
use libc;
186-
use private::intrinsics::{move_val_init};
186+
use unstable::intrinsics::{move_val_init};
187187
use ptr::addr_of;
188188
use ptr;
189189
use sys;

src/libcore/cleanup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn debug_mem() -> bool {
154154
#[cfg(notest)]
155155
#[lang="annihilate"]
156156
pub unsafe fn annihilate() {
157-
use rt::local_free;
157+
use unstable::lang::local_free;
158158
use io::WriterUtil;
159159
use io;
160160
use libc;

0 commit comments

Comments
 (0)