Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIP boxed closures #20578

Merged
merged 37 commits into from
Jan 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a291a80
register snapshot
Jan 5, 2015
37f62ae
std: remove remaining boxed closures
Jan 1, 2015
07a8e7c
syntax: remove remaining boxed closures
Jan 1, 2015
98fda87
conv_did: convert to "unboxed" closure
Jan 3, 2015
bd9eef7
DecodeInlinedItem: convert to "unboxed" closures
Jan 4, 2015
0cb34a3
EncodeInlinedItem: convert to "unboxed" closures
Jan 4, 2015
8570f0a
rustc: remove remaining boxed closures
Jan 4, 2015
977e151
typeck: remove remaining boxed closures
Jan 4, 2015
bf52e26
trans: remove remaining boxed closures
Jan 4, 2015
b4ccc90
driver: remove unboxed closures
Jan 5, 2015
3744850
compiletest: remove boxed closures
Jan 5, 2015
18e2026
coretest: remove/ignore tests
Jan 5, 2015
5f7f2c9
remove ty_closure
Jan 4, 2015
714a5b7
remove TyClosure
Jan 4, 2015
4e9c50e
remove AdjustAddEnv
Jan 4, 2015
8a6d7a6
remove mk_closure
Jan 4, 2015
865aabb
trans: remove Closure
Jan 5, 2015
58b0d74
syntax: make the closure type `f: |uint| -> bool` syntax obsolete
Jan 1, 2015
f258ee7
typeck: there are only unboxed closures now
Jan 4, 2015
799332f
syntax: remove dead code
Jan 4, 2015
5d6a6f5
rustc: remove dead code
Jan 4, 2015
6438261
trans: remove dead code
Jan 4, 2015
8d0d752
typeck: remove dead code
Jan 4, 2015
ca17d08
fix rpass tests
Jan 2, 2015
7d5b045
fix cfail tests
Jan 3, 2015
d6a948e
fix run-make test
Jan 5, 2015
1bbeb37
fix pretty tests
Jan 5, 2015
ef72659
fix debuginfo tests
Jan 5, 2015
a9ea4d0
fix benchmarks
Jan 5, 2015
ab0c7af
ignore boxed closure doctests in the guide/reference
Jan 5, 2015
79af277
address Niko's comments
Jan 5, 2015
f97b124
Fix ICE caused by forgotten bcx
nikomatsakis Jan 5, 2015
c98814b
Correctly "detuple" arguments when creating trait object shims for a …
nikomatsakis Jan 5, 2015
ec11f66
replace `f.call_mut(a, b, ..)` with `f(a, b, ..)`
Jan 5, 2015
a55011e
fix tests
Jan 5, 2015
97f870a
unignore and fix doctests in guide and reference
Jan 5, 2015
eb2506c
remove more stage0 stuff
Jan 5, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
return valid;
}

pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
-> test::TestDescAndFn {
pub fn make_test<F>(config: &Config, testfile: &Path, f: F) -> test::TestDescAndFn where
F: FnOnce() -> test::TestFn,
{
test::TestDescAndFn {
desc: test::TestDesc {
name: make_test_name(config, testfile),
Expand Down
4 changes: 3 additions & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
!val
}

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

let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
Expand Down
14 changes: 8 additions & 6 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,12 +1233,14 @@ enum TargetLocation {
ThisDirectory(Path),
}

fn make_compile_args(config: &Config,
props: &TestProps,
extras: Vec<String> ,
xform: |&Config, &Path| -> TargetLocation,
testfile: &Path)
-> ProcArgs {
fn make_compile_args<F>(config: &Config,
props: &TestProps,
extras: Vec<String> ,
xform: F,
testfile: &Path)
-> ProcArgs where
F: FnOnce(&Config, &Path) -> TargetLocation,
{
let xform_file = xform(config, testfile);
let target = if props.force_host {
config.host.as_slice()
Expand Down
6 changes: 4 additions & 2 deletions src/doc/guide-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ computation entirely. This could be done for the example above by adjusting the
`b.iter` call to

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

# fn main() {
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
# struct X;
# impl X { fn iter<T, F>(&self, _: F) where F: FnMut() -> T {} } let b = X;
b.iter(|| {
test::black_box(range(0u, 1000).fold(0, |old, new| old ^ new));
});
Expand Down
32 changes: 16 additions & 16 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4232,7 +4232,7 @@ arguments, really powerful things are possible.
Let's make a closure:

```{rust}
let add_one = |x| { 1 + x };
let add_one = |&: x| { 1 + x };

println!("The sum of 5 plus 1 is {}.", add_one(5));
```
Expand All @@ -4244,8 +4244,8 @@ binding name and two parentheses, just like we would for a named function.
Let's compare syntax. The two are pretty close:

```{rust}
let add_one = |x: i32| -> i32 { 1 + x };
fn add_one (x: i32) -> i32 { 1 + x }
let add_one = |&: x: i32| -> i32 { 1 + x };
fn add_one (x: i32) -> i32 { 1 + x }
```

As you may have noticed, closures infer their argument and return types, so you
Expand All @@ -4258,9 +4258,9 @@ this:

```{rust}
fn main() {
let x = 5;
let x: i32 = 5;

let printer = || { println!("x is: {}", x); };
let printer = |&:| { println!("x is: {}", x); };

printer(); // prints "x is: 5"
}
Expand All @@ -4276,7 +4276,7 @@ defined. The closure borrows any variables it uses, so this will error:
fn main() {
let mut x = 5;

let printer = || { println!("x is: {}", x); };
let printer = |&:| { println!("x is: {}", x); };

x = 6; // error: cannot assign to `x` because it is borrowed
}
Expand All @@ -4298,12 +4298,12 @@ now. We'll talk about them more in the "Threads" section of the guide.
Closures are most useful as an argument to another function. Here's an example:

```{rust}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
f(x) + f(x)
}

fn main() {
let square = |x: i32| { x * x };
let square = |&: x: i32| { x * x };

twice(5, square); // evaluates to 50
}
Expand All @@ -4312,15 +4312,15 @@ fn main() {
Let's break the example down, starting with `main`:

```{rust}
let square = |x: i32| { x * x };
let square = |&: x: i32| { x * x };
```

We've seen this before. We make a closure that takes an integer, and returns
its square.

```{rust}
# fn twice(x: i32, f: |i32| -> i32) -> i32 { f(x) + f(x) }
# let square = |x: i32| { x * x };
# fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 { f(x) + f(x) }
# let square = |&: x: i32| { x * x };
twice(5, square); // evaluates to 50
```

Expand All @@ -4343,8 +4343,8 @@ how the `|i32| -> i32` syntax looks a lot like our definition of `square`
above, if we added the return type in:

```{rust}
let square = |x: i32| -> i32 { x * x };
// |i32| -> i32
let square = |&: x: i32| -> i32 { x * x };
// |i32| -> i32
```

This function takes an `i32` and returns an `i32`.
Expand All @@ -4358,7 +4358,7 @@ Finally, `twice` returns an `i32` as well.
Okay, let's look at the body of `twice`:

```{rust}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
f(x) + f(x)
}
```
Expand All @@ -4376,7 +4376,7 @@ If we didn't want to give `square` a name, we could just define it inline.
This example is the same as the previous one:

```{rust}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
f(x) + f(x)
}

Expand All @@ -4389,7 +4389,7 @@ A named function's name can be used wherever you'd use a closure. Another
way of writing the previous example:

```{rust}
fn twice(x: i32, f: |i32| -> i32) -> i32 {
fn twice<F: Fn(i32) -> i32>(x: i32, f: F) -> i32 {
f(x) + f(x)
}

Expand Down
12 changes: 6 additions & 6 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ functions](#generic-functions).
trait Seq<T> {
fn len(&self) -> uint;
fn elt_at(&self, n: uint) -> T;
fn iter(&self, |T|);
fn iter<F>(&self, F) where F: Fn(T);
}
```

Expand Down Expand Up @@ -3218,7 +3218,7 @@ In this example, we define a function `ten_times` that takes a higher-order
function argument, and call it with a lambda expression as an argument.

```
fn ten_times(f: |int|) {
fn ten_times<F>(f: F) where F: Fn(int) {
let mut i = 0;
while i < 10 {
f(i);
Expand Down Expand Up @@ -3828,7 +3828,7 @@ fn add(x: int, y: int) -> int {

let mut x = add(5,7);

type Binop<'a> = |int,int|: 'a -> int;
type Binop = fn(int, int) -> int;
let bo: Binop = add;
x = bo(5,7);
```
Expand All @@ -3852,14 +3852,14 @@ An example of creating and calling a closure:
```rust
let captured_var = 10i;

let closure_no_args = || println!("captured_var={}", captured_var);
let closure_no_args = |&:| println!("captured_var={}", captured_var);

let closure_args = |arg: int| -> int {
let closure_args = |&: arg: int| -> int {
println!("captured_var={}, arg={}", captured_var, arg);
arg // Note lack of semicolon after 'arg'
};

fn call_closure(c1: ||, c2: |int| -> int) {
fn call_closure<F: Fn(), G: Fn(int) -> int>(c1: F, c2: G) {
c1();
c2(2);
}
Expand Down
15 changes: 0 additions & 15 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,6 @@ pub struct Bitv {
nbits: uint
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing)
impl Index<uint,bool> for Bitv {
#[inline]
fn index(&self, i: &uint) -> &bool {
if self.get(*i).expect("index out of bounds") {
&TRUE
} else {
&FALSE
}
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing)
impl Index<uint> for Bitv {
type Output = bool;
Expand Down
24 changes: 0 additions & 24 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,18 +877,6 @@ impl<K: Show, V: Show> Show for BTreeMap<K, V> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[stable]
impl<K: Ord, Sized? Q, V> Index<Q, V> for BTreeMap<K, V>
where Q: BorrowFrom<K> + Ord
{
fn index(&self, key: &Q) -> &V {
self.get(key).expect("no entry found for key")
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[stable]
impl<K: Ord, Sized? Q, V> Index<Q> for BTreeMap<K, V>
where Q: BorrowFrom<K> + Ord
Expand All @@ -900,18 +888,6 @@ impl<K: Ord, Sized? Q, V> Index<Q> for BTreeMap<K, V>
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[stable]
impl<K: Ord, Sized? Q, V> IndexMut<Q, V> for BTreeMap<K, V>
where Q: BorrowFrom<K> + Ord
{
fn index_mut(&mut self, key: &Q) -> &mut V {
self.get_mut(key).expect("no entry found for key")
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[stable]
impl<K: Ord, Sized? Q, V> IndexMut<Q> for BTreeMap<K, V>
where Q: BorrowFrom<K> + Ord
Expand Down
22 changes: 0 additions & 22 deletions src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,17 +1360,6 @@ impl<S: Writer, A: Hash<S>> Hash<S> for RingBuf<A> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[stable]
impl<A> Index<uint, A> for RingBuf<A> {
#[inline]
fn index<'a>(&'a self, i: &uint) -> &'a A {
self.get(*i).expect("Out of bounds access")
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[stable]
impl<A> Index<uint> for RingBuf<A> {
type Output = A;
Expand All @@ -1381,17 +1370,6 @@ impl<A> Index<uint> for RingBuf<A> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[stable]
impl<A> IndexMut<uint, A> for RingBuf<A> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A {
self.get_mut(*i).expect("Out of bounds access")
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[stable]
impl<A> IndexMut<uint> for RingBuf<A> {
type Output = A;
Expand Down
21 changes: 0 additions & 21 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,17 +1190,6 @@ impl<S: hash::Writer, T: Hash<S>> Hash<S> for Vec<T> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[experimental = "waiting on Index stability"]
impl<T> Index<uint,T> for Vec<T> {
#[inline]
fn index<'a>(&'a self, index: &uint) -> &'a T {
&self.as_slice()[*index]
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[experimental = "waiting on Index stability"]
impl<T> Index<uint> for Vec<T> {
type Output = T;
Expand All @@ -1211,16 +1200,6 @@ impl<T> Index<uint> for Vec<T> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
impl<T> IndexMut<uint,T> for Vec<T> {
#[inline]
fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
&mut self.as_mut_slice()[*index]
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
impl<T> IndexMut<uint> for Vec<T> {
type Output = T;

Expand Down
22 changes: 0 additions & 22 deletions src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,6 @@ impl<V> Extend<(uint, V)> for VecMap<V> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[stable]
impl<V> Index<uint, V> for VecMap<V> {
#[inline]
fn index<'a>(&'a self, i: &uint) -> &'a V {
self.get(i).expect("key not present")
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
impl<V> Index<uint> for VecMap<V> {
type Output = V;

Expand All @@ -537,17 +526,6 @@ impl<V> Index<uint> for VecMap<V> {
}
}

// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
#[stable]
impl<V> IndexMut<uint, V> for VecMap<V> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V {
self.get_mut(i).expect("key not present")
}
}

#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
#[stable]
impl<V> IndexMut<uint> for VecMap<V> {
type Output = V;
Expand Down
Loading