Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/incoming' into incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Mar 2, 2013
2 parents aa3505d + 2304fe6 commit 5515fd5
Show file tree
Hide file tree
Showing 58 changed files with 519 additions and 592 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You're not off the hook even if you just stick to documentation; code examples i
Pull requests will be treated as "review requests",
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.
Changes contributed via pull request should focus on a single issue at a time, like any other.
We will not look accept pull-requests that try to "sneak" unrelated changes in.
We will not accept pull-requests that try to "sneak" unrelated changes in.

Normally, all pull requests must include regression tests (see [Note-testsuite](https://github.com/mozilla/rust/wiki/Note-testsuite)) that test your change.
Occasionally, a change will be very difficult to test for.
Expand Down
142 changes: 43 additions & 99 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ function defined above on `[1, 2]` will instantiate type parameter `T`
with `int`, and require the closure parameter to have type
`fn(int)`.

The type parameters can also be explicitly supplied in a trailing
[path](#paths) component after the function name. This might be necessary
if there is not sufficient context to determine the type parameters. For
example, `sys::size_of::<u32>() == 4`.

Since a parameter type is opaque to the generic function, the set of
operations that can be performed on it is limited. Values of parameter
type can always be moved, but they can only be copied when the
Expand Down Expand Up @@ -1085,6 +1090,15 @@ let p = Point(10, 11);
let px: int = match p { Point(x, _) => x };
~~~~

A _unit-like struct_ is a structure without any fields, defined by leaving off the fields list entirely.
Such types will have a single value, just like the [unit value `()`](#unit-and-boolean-literals) of the unit type.
For example:

~~~~
struct Cookie;
let c = [Cookie, Cookie, Cookie, Cookie];
~~~~

### Enumerations

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

~~~~
# type Point = {x: float, y: float};
# struct Point {x: float, y: float};
# type Surface = int;
# type BoundingBox = {x: float, y: float, width: float, height: float};
# struct BoundingBox {x: float, y: float, width: float, height: float};
# trait Shape { fn draw(Surface); fn bounding_box() -> BoundingBox; }
# fn do_draw_circle(s: Surface, c: Circle) { }
type Circle = {radius: float, center: Point};
struct Circle {
radius: float,
center: Point,
}
impl Shape for Circle {
fn draw(s: Surface) { do_draw_circle(s, self); }
fn bounding_box() -> BoundingBox {
let r = self.radius;
{x: self.center.x - r, y: self.center.y - r,
BoundingBox{x: self.center.x - r, y: self.center.y - r,
width: 2.0 * r, height: 2.0 * r}
}
}
Expand Down Expand Up @@ -1590,7 +1607,8 @@ struct_expr : expr_path '{' ident ':' expr
[ ',' ident ':' expr ] *
[ ".." expr ] '}' |
expr_path '(' expr
[ ',' expr ] * ')'
[ ',' expr ] * ')' |
expr_path
~~~~~~~~

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

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

A _unit-like structure expression_ consists only of the [path](#paths) of a [structure item](#structures).

The following are examples of structure expressions:

~~~~
# struct Point { x: float, y: float }
# struct TuplePoint(float, float);
# mod game { pub struct User { name: &str, age: uint, score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10f, y: 20f};
TuplePoint(10f, 20f);
let u = game::User {name: "Joe", age: 35u, score: 100_000};
some_fn::<Cookie>(Cookie);
~~~~

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

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

> **Note:** In future versions of Rust, record expressions and [record types](#record-types) will be removed.
A [_record_](#record-types) _expression_ is one or more comma-separated
name-value pairs enclosed by braces. A fieldname can be any identifier,
and is separated from its value expression by a
colon. To indicate that a field is mutable, the `mut` keyword is
written before its name.

~~~~
{x: 10f, y: 20f};
{name: "Joe", age: 35u, score: 100_000};
{ident: "X", mut count: 0u};
~~~~

The order of the fields in a record expression is significant, and
determines the type of the resulting value. `{a: u8, b: u8}` and `{b:
u8, a: u8}` are two different fields.

A record expression can terminate with the syntax `..` followed by an
expression to denote a functional update. The expression following
`..` (the base) must be of a record type that includes at least all the
fields mentioned in the record expression. A new record will be
created, of the same type as the base expression, with the given
values for the fields that were explicitly specified, and the values
in the base record for all other fields. The ordering of the fields in
such a record expression is not significant.

~~~~
let base = {x: 1, y: 2, z: 3};
{y: 0, z: 10, .. base};
~~~~

### Method-call expressions

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

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

~~~~~~~~ {.field}
myrecord.myfield;
Expand Down Expand Up @@ -1905,8 +1896,10 @@ An example of three different swap expressions:
# let mut x = &mut [0];
# let mut a = &mut [0];
# let i = 0;
# let y = {mut z: 0};
# let b = {mut c: 0};
# struct S1 { z: int };
# struct S2 { c: int };
# let mut y = S1{z: 0};
# let mut b = S2{c: 0};
x <-> a;
x[i] <-> a[i];
Expand Down Expand Up @@ -2040,12 +2033,14 @@ an optional reference slot to serve as the function's output, bound to the
`lval` on the right hand side of the call. If the function eventually returns,
then the expression completes.

An example of a call expression:
Some examples of call expressions:

~~~~
# fn add(x: int, y: int) -> int { 0 }
# use core::from_str::FromStr::from_str;
let x: int = add(1, 2);
let pi = from_str::<f32>("3.14");
~~~~

### Lambda expressions
Expand Down Expand Up @@ -2328,42 +2323,6 @@ match x {
}
~~~~

Records and structures can also be pattern-matched and their fields bound to variables.
When matching fields of a record,
the fields being matched are specified first,
then a placeholder (`_`) represents the remaining fields.

~~~~
# type options = {choose: bool, size: ~str};
# type player = {player: ~str, stats: (), options: options};
# fn load_stats() { }
# fn choose_player(r: &player) { }
# fn next_player() { }
fn main() {
let r = {
player: ~"ralph",
stats: load_stats(),
options: {
choose: true,
size: ~"small"
}
};
match r {
{options: {choose: true, _}, _} => {
choose_player(&r)
}
{player: ref p, options: {size: ~"small", _}, _} => {
log(info, (copy *p) + ~" is small");
}
_ => {
next_player();
}
}
}
~~~~

Patterns that bind variables default to binding to a copy of the matched value. This can be made
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
Expand Down Expand Up @@ -2643,7 +2602,10 @@ the resulting `struct` value will always be laid out in memory in the order spec
The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
to restrict access to implementation-private data in a structure.

A `tuple struct` type is just like a structure type, except that the fields are anonymous.
A _tuple struct_ type is just like a structure type, except that the fields are anonymous.

A _unit-like struct_ type is like a structure type, except that it has no fields.
The one value constructed by the associated [structure expression](#structure-expression) is the only value that inhabits such a type.

### Enumerated types

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


### Record types

> **Note:** Records are not nominal types, thus do not directly support recursion, visibility control,
> out-of-order field initialization, or coherent trait implementation.
> Records are therefore deprecated and will be removed in future versions of Rust.
> [Structure types](#structure-types) should be used instead.
The record type-constructor forms a new heterogeneous product of values.
Fields of a record type are accessed by name and are arranged in memory in the order specified by the record type.

An example of a record type and its use:

~~~~
type Point = {x: int, y: int};
let p: Point = {x: 10, y: 11};
let px: int = p.x;
~~~~


### Pointer types

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

~~~~~~~~
let x = @{y: 10};
struct Foo { y: int }
let x = @Foo{y: 10};
assert x.y == 10;
~~~~~~~~

Expand Down
11 changes: 6 additions & 5 deletions doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ operator. For example, I could write:
# struct Point {x: float, y: float} // as before
# struct Size {w: float, h: float} // as before
# struct Rectangle {origin: Point, size: Size}
# let rect_stack = &{origin: Point {x: 1f, y: 2f}, size: Size {w: 3f, h: 4f}};
# let rect_managed = @{origin: Point {x: 3f, y: 4f}, size: Size {w: 3f, h: 4f}};
# let rect_unique = ~{origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}};
# let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, size: Size {w: 3f, h: 4f}};
# let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, size: Size {w: 3f, h: 4f}};
# let rect_unique = ~Rectangle {origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}};
# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f }
compute_distance(&rect_stack.origin, &rect_managed.origin);
~~~
Expand Down Expand Up @@ -274,13 +274,14 @@ the following function is legal:

~~~
# fn some_condition() -> bool { true }
# struct Foo { f: int }
fn example3() -> int {
let mut x = ~{f: 3};
let mut x = ~Foo {f: 3};
if some_condition() {
let y = &x.f; // -+ L
return *y; // |
} // -+
x = ~{f: 4};
x = ~Foo {f: 4};
...
# return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub mod raw {
use at_vec::{capacity, rustrt};
use cast::transmute;
use libc;
use private::intrinsics::{move_val_init};
use unstable::intrinsics::{move_val_init};
use ptr::addr_of;
use ptr;
use sys;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn debug_mem() -> bool {
#[cfg(notest)]
#[lang="annihilate"]
pub unsafe fn annihilate() {
use rt::local_free;
use unstable::lang::local_free;
use io::WriterUtil;
use io;
use libc;
Expand Down
Loading

5 comments on commit 5515fd5

@bors
Copy link
Contributor

@bors bors commented on 5515fd5 Mar 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at erickt@5515fd5

@bors
Copy link
Contributor

@bors bors commented on 5515fd5 Mar 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/incoming = 5515fd5 into auto

@bors
Copy link
Contributor

@bors bors commented on 5515fd5 Mar 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/incoming = 5515fd5 merged ok, testing candidate = afdd0b8

@bors
Copy link
Contributor

@bors bors commented on 5515fd5 Mar 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 5515fd5 Mar 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = afdd0b8

Please sign in to comment.