Skip to content

Commit 2dea679

Browse files
committed
---
yaml --- r: 109777 b: refs/heads/snap-stage3 c: d1c584e h: refs/heads/master i: 109775: c96bf02 v: v3
1 parent fcb53e8 commit 2dea679

33 files changed

+294
-170
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4e9e25907b6c63e3bde3dd122160ec07ef1ba6b9
4+
refs/heads/snap-stage3: d1c584e41bc4f7c49123911dd93c2b3db38b0f8f
55
refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/rust.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3420,8 +3420,21 @@ x = bo(5,7);
34203420

34213421
### Closure types
34223422

3423-
The type of a closure mapping an input of type `A` to an output of type `B` is `|A| -> B`. A closure with no arguments or return values has type `||`.
3423+
~~~~ {.notrust .ebnf .notation}
3424+
closure_type := [ 'unsafe' ] [ '<' lifetime-list '>' ] '|' arg-list '|'
3425+
[ ':' bound-list ] [ '->' type ]
3426+
procedure_type := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')'
3427+
[ ':' bound-list ] [ '->' type ]
3428+
lifetime-list := lifetime | lifetime ',' lifetime-list
3429+
arg-list := ident ':' type | ident ':' type ',' arg-list
3430+
bound-list := bound | bound '+' bound-list
3431+
bound := path | lifetime
3432+
~~~~
34243433

3434+
The type of a closure mapping an input of type `A` to an output of type `B` is
3435+
`|A| -> B`. A closure with no arguments or return values has type `||`.
3436+
Similarly, a procedure mapping `A` to `B` is `proc(A) -> B` and a no-argument
3437+
and no-return value closure has type `proc()`.
34253438

34263439
An example of creating and calling a closure:
34273440

@@ -3444,6 +3457,30 @@ call_closure(closure_no_args, closure_args);
34443457

34453458
```
34463459

3460+
Unlike closures, procedures may only be invoked once, but own their
3461+
environment, and are allowed to move out of their environment. Procedures are
3462+
allocated on the heap (unlike closures). An example of creating and calling a
3463+
procedure:
3464+
3465+
```rust
3466+
let string = ~"Hello";
3467+
3468+
// Creates a new procedure, passing it to the `spawn` function.
3469+
spawn(proc() {
3470+
println!("{} world!", string);
3471+
});
3472+
3473+
// the variable `string` has been moved into the previous procedure, so it is
3474+
// no longer usable.
3475+
3476+
3477+
// Create an invoke a procedure. Note that the procedure is *moved* when
3478+
// invoked, so it cannot be invoked again.
3479+
let f = proc(n: int) { n + 22 };
3480+
println!("answer: {}", f(20));
3481+
3482+
```
3483+
34473484
### Object types
34483485

34493486
Every trait item (see [traits](#traits)) defines a type with the same name as the trait.

branches/snap-stage3/src/libsyntax/parse/obsolete.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ pub enum ObsoleteSyntax {
3636
ObsoleteEnumWildcard,
3737
ObsoleteStructWildcard,
3838
ObsoleteVecDotDotWildcard,
39-
ObsoleteBoxedClosure,
40-
ObsoleteClosureType,
4139
ObsoleteMultipleImport,
4240
ObsoleteManagedPattern,
4341
ObsoleteManagedString,
@@ -111,16 +109,6 @@ impl<'a> ParserObsoleteMethods for Parser<'a> {
111109
"vec slice wildcard",
112110
"use `..` instead of `.._` for matching slices"
113111
),
114-
ObsoleteBoxedClosure => (
115-
"managed or owned closure",
116-
"managed closures have been removed and owned closures are \
117-
now written `proc()`"
118-
),
119-
ObsoleteClosureType => (
120-
"closure type",
121-
"closures are now written `|A| -> B` rather than `&fn(A) -> \
122-
B`."
123-
),
124112
ObsoleteMultipleImport => (
125113
"multiple imports",
126114
"only one import is allowed per `use` statement"

0 commit comments

Comments
 (0)