Skip to content

Commit 470dd86

Browse files
committed
---
yaml --- r: 150621 b: refs/heads/try2 c: d1c584e h: refs/heads/master i: 150619: b427f5c v: v3
1 parent c7e4333 commit 470dd86

33 files changed

+294
-170
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: 4e9e25907b6c63e3bde3dd122160ec07ef1ba6b9
8+
refs/heads/try2: d1c584e41bc4f7c49123911dd93c2b3db38b0f8f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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)