Skip to content

Commit 95bc9ea

Browse files
committed
Remove REC, change related tests/docs
1 parent 0fd1b58 commit 95bc9ea

25 files changed

+74
-335
lines changed

doc/rust.md

+14-95
Original file line numberDiff line numberDiff line change
@@ -1285,19 +1285,22 @@ An _implementation_ is an item that implements a [trait](#traits) for a specific
12851285
Implementations are defined with the keyword `impl`.
12861286

12871287
~~~~
1288-
# type Point = {x: float, y: float};
1288+
# struct Point {x: float, y: float};
12891289
# type Surface = int;
1290-
# type BoundingBox = {x: float, y: float, width: float, height: float};
1290+
# struct BoundingBox {x: float, y: float, width: float, height: float};
12911291
# trait Shape { fn draw(Surface); fn bounding_box() -> BoundingBox; }
12921292
# fn do_draw_circle(s: Surface, c: Circle) { }
12931293
1294-
type Circle = {radius: float, center: Point};
1294+
struct Circle {
1295+
radius: float,
1296+
center: Point,
1297+
}
12951298
12961299
impl Shape for Circle {
12971300
fn draw(s: Surface) { do_draw_circle(s, self); }
12981301
fn bounding_box() -> BoundingBox {
12991302
let r = self.radius;
1300-
{x: self.center.x - r, y: self.center.y - r,
1303+
BoundingBox{x: self.center.x - r, y: self.center.y - r,
13011304
width: 2.0 * r, height: 2.0 * r}
13021305
}
13031306
}
@@ -1637,38 +1640,6 @@ rec_expr : '{' ident ':' expr
16371640
[ ".." expr ] '}'
16381641
~~~~~~~~
16391642

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-
16721643
### Method-call expressions
16731644

16741645
~~~~~~~~{.ebnf .gram}
@@ -1689,7 +1660,7 @@ field_expr : expr '.' ident
16891660

16901661
A _field expression_ consists of an expression followed by a single dot and an identifier,
16911662
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).
1663+
A field expression denotes a field of a [structure](#structure-types).
16931664

16941665
~~~~~~~~ {.field}
16951666
myrecord.myfield;
@@ -1905,8 +1876,10 @@ An example of three different swap expressions:
19051876
# let mut x = &mut [0];
19061877
# let mut a = &mut [0];
19071878
# let i = 0;
1908-
# let y = {mut z: 0};
1909-
# let b = {mut c: 0};
1879+
# struct S1 { z: int };
1880+
# struct S2 { c: int };
1881+
# let mut y = S1{z: 0};
1882+
# let mut b = S2{c: 0};
19101883
19111884
x <-> a;
19121885
x[i] <-> a[i];
@@ -2328,42 +2301,6 @@ match x {
23282301
}
23292302
~~~~
23302303

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-
23672304
Patterns that bind variables default to binding to a copy of the matched value. This can be made
23682305
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
23692306
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
@@ -2692,25 +2629,6 @@ let a: List<int> = Cons(7, @Cons(13, @Nil));
26922629
~~~~
26932630

26942631

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-
27142632
### Pointer types
27152633

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

30422960
~~~~~~~~
3043-
let x = @{y: 10};
2961+
struct Foo { y: int }
2962+
let x = @Foo{y: 10};
30442963
assert x.y == 10;
30452964
~~~~~~~~
30462965

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/dvec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -62,17 +62,17 @@ pub struct DVec<A> {
6262

6363
/// Creates a new, empty dvec
6464
pub pure fn DVec<A>() -> DVec<A> {
65-
DVec {mut data: ~[]}
65+
DVec {data: ~[]}
6666
}
6767

6868
/// Creates a new dvec with a single element
6969
pub pure fn from_elem<A>(e: A) -> DVec<A> {
70-
DVec {mut data: ~[e]}
70+
DVec {data: ~[e]}
7171
}
7272

7373
/// Creates a new dvec with the contents of a vector
7474
pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> {
75-
DVec {mut data: v}
75+
DVec {data: v}
7676
}
7777

7878
/// Consumes the vector and returns its contents

src/libcore/os.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -322,8 +322,8 @@ pub struct Pipe { mut in: c_int, mut out: c_int }
322322
#[cfg(unix)]
323323
pub fn pipe() -> Pipe {
324324
unsafe {
325-
let mut fds = Pipe {mut in: 0 as c_int,
326-
mut out: 0 as c_int };
325+
let mut fds = Pipe {in: 0 as c_int,
326+
out: 0 as c_int };
327327
assert (libc::pipe(&mut fds.in) == (0 as c_int));
328328
return Pipe {in: fds.in, out: fds.out};
329329
}
@@ -339,8 +339,8 @@ pub fn pipe() -> Pipe {
339339
// fully understand. Here we explicitly make the pipe non-inheritable,
340340
// which means to pass it to a subprocess they need to be duplicated
341341
// first, as in rust_run_program.
342-
let mut fds = Pipe { mut in: 0 as c_int,
343-
mut out: 0 as c_int };
342+
let mut fds = Pipe {in: 0 as c_int,
343+
out: 0 as c_int };
344344
let res = libc::pipe(&mut fds.in, 1024 as c_uint,
345345
(libc::O_BINARY | libc::O_NOINHERIT) as c_int);
346346
assert (res == 0 as c_int);
@@ -566,13 +566,17 @@ pub fn path_exists(p: &Path) -> bool {
566566
*
567567
* If the given path is relative, return it prepended with the current working
568568
* directory. If the given path is already an absolute path, return it
569-
* as is. This is a shortcut for calling os::getcwd().unsafe_join(p)
569+
* as is.
570570
*/
571571
// NB: this is here rather than in path because it is a form of environment
572572
// querying; what it does depends on the process working directory, not just
573573
// the input paths.
574574
pub fn make_absolute(p: &Path) -> Path {
575-
getcwd().unsafe_join(p)
575+
if p.is_absolute {
576+
copy *p
577+
} else {
578+
getcwd().push_many(p.components)
579+
}
576580
}
577581

578582

src/libcore/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -300,15 +300,15 @@ impl<T:Ord> Ord for &const T {
300300
pub fn test() {
301301
unsafe {
302302
struct Pair {mut fst: int, mut snd: int};
303-
let mut p = Pair {mut fst: 10, mut snd: 20};
303+
let mut p = Pair {fst: 10, snd: 20};
304304
let pptr: *mut Pair = &mut p;
305305
let iptr: *mut int = cast::reinterpret_cast(&pptr);
306306
assert (*iptr == 10);;
307307
*iptr = 30;
308308
assert (*iptr == 30);
309309
assert (p.fst == 30);;
310310

311-
*pptr = Pair {mut fst: 50, mut snd: 60};
311+
*pptr = Pair {fst: 50, snd: 60};
312312
assert (*iptr == 50);
313313
assert (p.fst == 50);
314314
assert (p.snd == 60);

src/libstd/ebml.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -219,7 +219,7 @@ pub mod reader {
219219
}
220220

221221
pub fn Decoder(d: Doc) -> Decoder {
222-
Decoder { mut parent: d, mut pos: d.start }
222+
Decoder { parent: d, pos: d.start }
223223
}
224224

225225
priv impl Decoder {

src/libstd/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -87,7 +87,7 @@ enum Sem<Q> = Exclusive<SemInner<Q>>;
8787
#[doc(hidden)]
8888
fn new_sem<Q:Owned>(count: int, q: Q) -> Sem<Q> {
8989
Sem(exclusive(SemInner {
90-
mut count: count, waiters: new_waitqueue(), blocked: q }))
90+
count: count, waiters: new_waitqueue(), blocked: q }))
9191
}
9292
#[doc(hidden)]
9393
fn new_sem_and_signal(count: int, num_condvars: uint)

src/libsyntax/parse/parser.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -1093,15 +1093,10 @@ pub impl Parser {
10931093
self.mk_expr(lo, hi, expr_tup(es))
10941094
}
10951095
} else if *self.token == token::LBRACE {
1096-
if self.looking_at_record_literal() {
1097-
ex = self.parse_record_literal();
1098-
hi = self.span.hi;
1099-
} else {
1100-
self.bump();
1101-
let blk = self.parse_block_tail(lo, default_blk);
1102-
return self.mk_expr(blk.span.lo, blk.span.hi,
1103-
expr_block(blk));
1104-
}
1096+
self.bump();
1097+
let blk = self.parse_block_tail(lo, default_blk);
1098+
return self.mk_expr(blk.span.lo, blk.span.hi,
1099+
expr_block(blk));
11051100
} else if token::is_bar(*self.token) {
11061101
return self.parse_lambda_expr();
11071102
} else if self.eat_keyword(~"if") {
@@ -1223,6 +1218,7 @@ pub impl Parser {
12231218
self.bump();
12241219
let mut fields = ~[];
12251220
let mut base = None;
1221+
12261222
fields.push(self.parse_field(token::COLON));
12271223
while *self.token != token::RBRACE {
12281224
if self.try_parse_obsolete_with() {

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
12131213
print_expr(s, expr);
12141214
end(s);
12151215
}
1216-
_ => word(s.s, ~",")
1216+
_ => (word(s.s, ~","))
12171217
}
12181218
word(s.s, ~"}");
12191219
}

src/test/compile-fail/autoderef-full-lval.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
// except according to those terms.
1010

1111
// error-pattern: mismatched types
12-
type clam = {x: @int, y: @int};
12+
struct clam {
13+
x: @int,
14+
y: @int,
15+
}
1316

14-
type fish = {a: @int};
17+
struct fish {
18+
a: @int,
19+
}
1520

1621
fn main() {
17-
let a: clam = {x: @1, y: @2};
18-
let b: clam = {x: @10, y: @20};
22+
let a: clam = clam{x: @1, y: @2};
23+
let b: clam = clam{x: @10, y: @20};
1924
let z: int = a.x + b.y;
2025
log(debug, z);
2126
assert (z == 21);
22-
let forty: fish = {a: @40};
23-
let two: fish = {a: @2};
27+
let forty: fish = fish{a: @40};
28+
let two: fish = fish{a: @2};
2429
let answer: int = forty.a + two.a;
2530
log(debug, answer);
2631
assert (answer == 42);

0 commit comments

Comments
 (0)