Skip to content

Commit 05f55ad

Browse files
committed
---
yaml --- r: 169905 b: refs/heads/auto c: a56e7ae h: refs/heads/master i: 169903: 2ea8d5f v: v3
1 parent 19e415c commit 05f55ad

File tree

352 files changed

+3258
-7222
lines changed

Some content is hidden

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

352 files changed

+3258
-7222
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: d46b8f1fce6da33df8bf7c8c74c2da7bc023f993
13+
refs/heads/auto: a56e7aee81733485d6edd415ab383347232e3c36
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/compiletest/compiletest.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,8 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
339339
return valid;
340340
}
341341

342-
pub fn make_test<F>(config: &Config, testfile: &Path, f: F) -> test::TestDescAndFn where
343-
F: FnOnce() -> test::TestFn,
344-
{
342+
pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
343+
-> test::TestDescAndFn {
345344
test::TestDescAndFn {
346345
desc: test::TestDesc {
347346
name: make_test_name(config, testfile),

branches/auto/src/compiletest/header.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
220220
!val
221221
}
222222

223-
fn iter_header<F>(testfile: &Path, mut it: F) -> bool where
224-
F: FnMut(&str) -> bool,
225-
{
223+
fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
226224
use std::io::{BufferedReader, File};
227225

228226
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());

branches/auto/src/compiletest/runtest.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,14 +1233,12 @@ enum TargetLocation {
12331233
ThisDirectory(Path),
12341234
}
12351235

1236-
fn make_compile_args<F>(config: &Config,
1237-
props: &TestProps,
1238-
extras: Vec<String> ,
1239-
xform: F,
1240-
testfile: &Path)
1241-
-> ProcArgs where
1242-
F: FnOnce(&Config, &Path) -> TargetLocation,
1243-
{
1236+
fn make_compile_args(config: &Config,
1237+
props: &TestProps,
1238+
extras: Vec<String> ,
1239+
xform: |&Config, &Path| -> TargetLocation,
1240+
testfile: &Path)
1241+
-> ProcArgs {
12441242
let xform_file = xform(config, testfile);
12451243
let target = if props.force_host {
12461244
config.host.as_slice()

branches/auto/src/doc/guide-ownership.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ fn add_one(num: &int) -> int {
230230
```
231231

232232
Rust has a feature called 'lifetime elision,' which allows you to not write
233-
lifetime annotations in certain circumstances. This is one of them. Without
234-
eliding the lifetimes, `add_one` looks like this:
233+
lifetime annotations in certain circumstances. This is one of them. We will
234+
cover the others later. Without eliding the lifetimes, `add_one` looks like
235+
this:
235236

236237
```rust
237238
fn add_one<'a>(num: &'a int) -> int {
@@ -449,6 +450,80 @@ This is the simplest kind of multiple ownership possible. For example, there's
449450
also `Arc<T>`, which uses more expensive atomic instructions to be the
450451
thread-safe counterpart of `Rc<T>`.
451452

453+
## Lifetime Elision
454+
455+
Earlier, we mentioned 'lifetime elision,' a feature of Rust which allows you to
456+
not write lifetime annotations in certain circumstances. All references have a
457+
lifetime, and so if you elide a lifetime (like `&T` instead of `&'a T`), Rust
458+
will do three things to determine what those lifetimes should be.
459+
460+
When talking about lifetime elision, we use the term 'input lifetime' and
461+
'output lifetime'. An 'input liftime' is a lifetime associated with a parameter
462+
of a function, and an 'output lifetime' is a lifetime associated with the return
463+
value of a function. For example, this function has an input lifetime:
464+
465+
```{rust,ignore}
466+
fn foo<'a>(bar: &'a str)
467+
```
468+
469+
This one has an output lifetime:
470+
471+
```{rust,ignore}
472+
fn foo<'a>() -> &'a str
473+
```
474+
475+
This one has a lifetime in both positions:
476+
477+
```{rust,ignore}
478+
fn foo<'a>(bar: &'a str) -> &'a str
479+
```
480+
481+
Here are the three rules:
482+
483+
* Each elided lifetime in a function's arguments becomes a distinct lifetime
484+
parameter.
485+
486+
* If there is exactly one input lifetime, elided or not, that lifetime is
487+
assigned to all elided lifetimes in the return values of that function..
488+
489+
* If there are multiple input lifetimes, but one of them is `&self` or `&mut
490+
self`, the lifetime of `self` is assigned to all elided output lifetimes.
491+
492+
Otherwise, it is an error to elide an output lifetime.
493+
494+
### Examples
495+
496+
Here are some examples of functions with elided lifetimes, and the version of
497+
what the elided lifetimes are expand to:
498+
499+
```{rust,ignore}
500+
fn print(s: &str); // elided
501+
fn print<'a>(s: &'a str); // expanded
502+
503+
fn debug(lvl: uint, s: &str); // elided
504+
fn debug<'a>(lvl: uint, s: &'a str); // expanded
505+
506+
// In the preceeding example, `lvl` doesn't need a lifetime because it's not a
507+
// reference (`&`). Only things relating to references (such as a `struct`
508+
// which contains a reference) need lifetimes.
509+
510+
fn substr(s: &str, until: uint) -> &str; // elided
511+
fn substr<'a>(s: &'a str, until: uint) -> &'a str; // expanded
512+
513+
fn get_str() -> &str; // ILLEGAL, no inputs
514+
515+
fn frob(s: &str, t: &str) -> &str; // ILLEGAL, two inputs
516+
517+
fn get_mut(&mut self) -> &mut T; // elided
518+
fn get_mut<'a>(&'a mut self) -> &'a mut T; // expanded
519+
520+
fn args<T:ToCStr>(&mut self, args: &[T]) -> &mut Command // elided
521+
fn args<'a, 'b, T:ToCStr>(&'a mut self, args: &'b [T]) -> &'a mut Command // expanded
522+
523+
fn new(buf: &mut [u8]) -> BufWriter; // elided
524+
fn new<'a>(buf: &'a mut [u8]) -> BufWriter<'a> // expanded
525+
```
526+
452527
# Related Resources
453528

454529
Coming Soon.

branches/auto/src/doc/guide-testing.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,7 @@ computation entirely. This could be done for the example above by adjusting the
537537
`b.iter` call to
538538

539539
```rust
540-
# struct X;
541-
# impl X { fn iter<T, F>(&self, _: F) where F: FnMut() -> T {} } let b = X;
540+
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
542541
b.iter(|| {
543542
// note lack of `;` (could also use an explicit `return`).
544543
range(0u, 1000).fold(0, |old, new| old ^ new)
@@ -553,8 +552,7 @@ argument as used.
553552
extern crate test;
554553

555554
# fn main() {
556-
# struct X;
557-
# impl X { fn iter<T, F>(&self, _: F) where F: FnMut() -> T {} } let b = X;
555+
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
558556
b.iter(|| {
559557
test::black_box(range(0u, 1000).fold(0, |old, new| old ^ new));
560558
});

branches/auto/src/doc/guide.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,7 +4232,7 @@ arguments, really powerful things are possible.
42324232
Let's make a closure:
42334233
42344234
```{rust}
4235-
let add_one = |&: x| { 1 + x };
4235+
let add_one = |x| { 1 + x };
42364236
42374237
println!("The sum of 5 plus 1 is {}.", add_one(5));
42384238
```
@@ -4244,8 +4244,8 @@ binding name and two parentheses, just like we would for a named function.
42444244
Let's compare syntax. The two are pretty close:
42454245
42464246
```{rust}
4247-
let add_one = |&: x: i32| -> i32 { 1 + x };
4248-
fn add_one (x: i32) -> i32 { 1 + x }
4247+
let add_one = |x: i32| -> i32 { 1 + x };
4248+
fn add_one (x: i32) -> i32 { 1 + x }
42494249
```
42504250
42514251
As you may have noticed, closures infer their argument and return types, so you
@@ -4258,9 +4258,9 @@ this:
42584258
42594259
```{rust}
42604260
fn main() {
4261-
let x: i32 = 5;
4261+
let x = 5;
42624262
4263-
let printer = |&:| { println!("x is: {}", x); };
4263+
let printer = || { println!("x is: {}", x); };
42644264
42654265
printer(); // prints "x is: 5"
42664266
}
@@ -4276,7 +4276,7 @@ defined. The closure borrows any variables it uses, so this will error:
42764276
fn main() {
42774277
let mut x = 5;
42784278
4279-
let printer = |&:| { println!("x is: {}", x); };
4279+
let printer = || { println!("x is: {}", x); };
42804280
42814281
x = 6; // error: cannot assign to `x` because it is borrowed
42824282
}
@@ -4298,12 +4298,12 @@ now. We'll talk about them more in the "Threads" section of the guide.
42984298
Closures are most useful as an argument to another function. Here's an example:
42994299
43004300
```{rust}
4301-
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
4301+
fn twice(x: i32, f: |i32| -> i32) -> i32 {
43024302
f(x) + f(x)
43034303
}
43044304
43054305
fn main() {
4306-
let square = |&: x: i32| { x * x };
4306+
let square = |x: i32| { x * x };
43074307
43084308
twice(5, square); // evaluates to 50
43094309
}
@@ -4312,15 +4312,15 @@ fn main() {
43124312
Let's break the example down, starting with `main`:
43134313
43144314
```{rust}
4315-
let square = |&: x: i32| { x * x };
4315+
let square = |x: i32| { x * x };
43164316
```
43174317
43184318
We've seen this before. We make a closure that takes an integer, and returns
43194319
its square.
43204320
43214321
```{rust}
4322-
# fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 { f(x) + f(x) }
4323-
# let square = |&: x: i32| { x * x };
4322+
# fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) }
4323+
# let square = |x: i32| { x * x };
43244324
twice(5, square); // evaluates to 50
43254325
```
43264326
@@ -4343,8 +4343,8 @@ how the `|i32| -> i32` syntax looks a lot like our definition of `square`
43434343
above, if we added the return type in:
43444344
43454345
```{rust}
4346-
let square = |&: x: i32| -> i32 { x * x };
4347-
// |i32| -> i32
4346+
let square = |x: i32| -> i32 { x * x };
4347+
// |i32| -> i32
43484348
```
43494349
43504350
This function takes an `i32` and returns an `i32`.
@@ -4358,7 +4358,7 @@ Finally, `twice` returns an `i32` as well.
43584358
Okay, let's look at the body of `twice`:
43594359
43604360
```{rust}
4361-
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
4361+
fn twice(x: i32, f: |i32| -> i32) -> i32 {
43624362
f(x) + f(x)
43634363
}
43644364
```
@@ -4376,7 +4376,7 @@ If we didn't want to give `square` a name, we could just define it inline.
43764376
This example is the same as the previous one:
43774377
43784378
```{rust}
4379-
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
4379+
fn twice(x: i32, f: |i32| -> i32) -> i32 {
43804380
f(x) + f(x)
43814381
}
43824382
@@ -4389,7 +4389,7 @@ A named function's name can be used wherever you'd use a closure. Another
43894389
way of writing the previous example:
43904390
43914391
```{rust}
4392-
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
4392+
fn twice(x: i32, f: |i32| -> i32) -> i32 {
43934393
f(x) + f(x)
43944394
}
43954395

0 commit comments

Comments
 (0)