Commit Graph

35118 Commits

Author SHA1 Message Date
Nicholas Bishop
a333e013fc Fix typo: intuitive -> unintuitive 2014-12-14 13:38:46 -05:00
bors
93c0610096 auto merge of #19725 : vadimcn/rust/inst-path, r=alexcrichton
Change default installation directory to %SYSTEMDRIVE%\Rust.
Modify user PATH, rather than system PATH.
2014-12-14 16:07:32 +00:00
bors
52f7a4a351 auto merge of #19338 : nikomatsakis/rust/unboxed-closure-purge-the-proc, r=acrichto
They are replaced with unboxed closures.

cc @pcwalton @aturon 

This is a [breaking-change]. Mostly, uses of `proc()` simply need to be converted to `move||` (unboxed closures), but in some cases the adaptations required are more complex (particularly for library authors). A detailed write-up can be found here: http://smallcultfollowing.com/babysteps/blog/2014/11/26/purging-proc/

The commits are ordered to emphasize the more important changes, but are not truly standalone.
2014-12-14 11:37:27 +00:00
bors
3a9305ce82 auto merge of #19690 : barosl/rust/struct-variant-as-a-function-ice, r=alexcrichton
Unlike a tuple variant constructor which can be called as a function, a struct variant constructor is not a function, so cannot be called.

If the user tries to assign the constructor to a variable, an ICE occurs, because there is no way to use it later. So we should stop the constructor from being used like that.

A similar mechanism already exists for a normal struct, as it prohibits a struct from being resolved. This commit does the same for a struct variant.

This commit also includes some changes to the existing tests.

Fixes #19452.
2014-12-14 09:22:24 +00:00
Niko Matsakis
f6d60f3208 Stop using diagnostics to avoid merge conflicts. 2014-12-14 04:21:57 -05:00
Niko Matsakis
840ce00a9b Temporarily remove issue #14039; it is fixed and re-added by PR #19438 2014-12-14 04:21:57 -05:00
Niko Matsakis
9c9253e859 Add some tests for obsolete code, sugar used in appropriate ways. 2014-12-14 04:21:57 -05:00
Niko Matsakis
0fefd835f2 Update emacs and vi modes. 2014-12-14 04:21:57 -05:00
Niko Matsakis
112faabf94 Update guide/intro to take into account the removal of proc.
cc @steveklabnick
2014-12-14 04:21:57 -05:00
Niko Matsakis
27676d9aa9 Delete tests that are either no longer relevant or which have
duplicate tests around object types.
2014-12-14 04:21:56 -05:00
Niko Matsakis
5c3d398919 Mostly rote conversion of proc() to move|| (and occasionally Thunk::new) 2014-12-14 04:21:56 -05:00
Niko Matsakis
394f6846b8 Rewrite WorkItem not to use proc(). 2014-12-14 04:21:56 -05:00
Niko Matsakis
d8e51ea0e2 Patch rustdoc to include missing types, make the match exhaustive
to prevent such oversights in the future.
2014-12-14 04:21:56 -05:00
Niko Matsakis
d258d68db6 Remove proc types/expressions from the parser, compiler, and
language. Recommend `move||` instead.
2014-12-14 04:21:56 -05:00
Niko Matsakis
9cc8453a78 Adjust feature gates to allow for parenthetical notation to be used
with the fn traits
2014-12-14 04:21:56 -05:00
Niko Matsakis
698db04a8d Purge the hack that allows FnOnce to be used with a by-value self method. Besides being yucky, it will cause problems if we try to make all traits implement themselves, which would make a lot of things in life easier. Also, it was inextricably linked to Box, which was not the intention. We can work around its absence, so better to reimplement it later in a more thorough fashion. 2014-12-14 04:21:56 -05:00
Niko Matsakis
d61338172f Rewrite threading infrastructure, introducing Thunk to represent
boxed `FnOnce` closures.
2014-12-14 04:21:56 -05:00
bors
10ac5b72f1 auto merge of #19677 : japaric/rust/deprecate-tupleN, r=alexcrichton
r? @alexcrichton or anyone else
closes #18006
2014-12-14 07:07:31 +00:00
bors
f07526a999 auto merge of #19669 : alfie/rust/master, r=sanxiyn 2014-12-14 01:07:31 +00:00
Jorge Aparicio
029789b98c Get rid of all the remaining uses of refN/valN/mutN/TupleN 2014-12-13 20:04:41 -05:00
Jorge Aparicio
17a9c2764f libcore: allow deprecated valN methods on doc tests 2014-12-13 20:04:41 -05:00
Jorge Aparicio
8720174bf2 libgraphviz: use tuple indexing 2014-12-13 20:04:41 -05:00
Jorge Aparicio
778be74cbb libcoretest: use tuple indexing 2014-12-13 20:04:41 -05:00
Jorge Aparicio
e792338318 librustdoc: use tuple indexing 2014-12-13 20:04:41 -05:00
Jorge Aparicio
0c5d22c9cd librustc_trans: use tuple indexing 2014-12-13 20:04:41 -05:00
Jorge Aparicio
821b836634 librustc: use tuple indexing 2014-12-13 20:04:41 -05:00
Jorge Aparicio
c434954b27 libsyntax: use tuple indexing 2014-12-13 20:04:40 -05:00
Jorge Aparicio
4fd6a99851 libregex: use tuple indexing 2014-12-13 20:04:40 -05:00
Jorge Aparicio
fe48a65aaa libstd: use tuple indexing 2014-12-13 20:04:40 -05:00
Jorge Aparicio
4deb27e67a libcollections: use tuple indexing 2014-12-13 20:04:40 -05:00
Jorge Aparicio
2e8963debc libunicode: use tuple indexing 2014-12-13 20:04:40 -05:00
Jorge Aparicio
0c9b6ae6a8 Deprecate the TupleN traits 2014-12-13 20:04:40 -05:00
bors
444fa1b7cf auto merge of #19467 : japaric/rust/uc, r=alexcrichton
This PR moves almost all our current uses of closures, both in public API and internal uses, to the new "unboxed" closures system.

In most cases, downstream code that *only uses* closures will continue to work as it is. The reason is that the `|| {}` syntax can be inferred either as a boxed or an "unboxed" closure according to the context. For example the following code will continue to work:

``` rust
some_option.map(|x| x.transform_with(upvar))
```

And will get silently upgraded to an "unboxed" closure.

In some other cases, it may be necessary to "annotate" which `Fn*` trait the closure implements:

```
// Change this
|x| { /* body */}
// to either of these
|: x| { /* body */}  // closure implements the FnOnce trait
|&mut : x| { /* body */}  // FnMut
|&: x| { /* body */}  // Fn
```

This mainly occurs when the closure is assigned to a variable first, and then passed to a function/method.

``` rust
let closure = |: x| x.transform_with(upvar);
some.option.map(closure)
```

(It's very likely that in the future, an improved inference engine will make this annotation unnecessary)

Other cases that require annotation are closures that implement some trait via a blanket `impl`, for example:

- `std::finally::Finally`
- `regex::Replacer`
- `std::str::CharEq`

``` rust
string.trim_left_chars(|c: char| c.is_whitespace())
//~^ ERROR: the trait `Fn<(char,), bool>` is not implemented for the type `|char| -> bool`
string.trim_left_chars(|&: c: char| c.is_whitespace())  // OK
```

Finally, all implementations of traits that contain boxed closures in the arguments of their methods are now broken. And will need to be updated to use unboxed closures. These are the main affected traits:

- `serialize::Decoder`
- `serialize::DecoderHelpers`
- `serialize::Encoder`
- `serialize::EncoderHelpers`
- `rustrt::ToCStr`

For example, change this:

``` rust
// libserialize/json.rs
impl<'a> Encoder<io::IoError> for Encoder<'a> {
    fn emit_enum(&mut self,
                 _name: &str,
                 f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
        f(self)
    }
}
```

to:

``` rust
// libserialize/json.rs
impl<'a> Encoder<io::IoError> for Encoder<'a> {
    fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult where
        F: FnOnce(&mut Encoder<'a>) -> EncodeResult
    {
        f(self)
    }
}
```

[breaking-change]

---

### How the `Fn*` bound has been selected

I've chosen the bounds to make the functions/structs as "generic as possible", i.e. to let them allow the maximum amount of input.

- An `F: FnOnce` bound accepts the three kinds of closures: `|:|`, `|&mut:|` and `|&:|`.
- An `F: FnMut` bound only accepts "non-consuming" closures: `|&mut:|` and `|&:|`.
- An `F: Fn` bound only accept the "immutable environment" closures: `|&:|`.

This means that whenever possible the `FnOnce` bound has been used, if the `FnOnce` bound couldn't be used, then the `FnMut` was used. The `Fn` bound was never used in the whole repository.

The `FnMut` bound was the most used, because it resembles the semantics of the current boxed closures: the closure can modify its environment, and the closure may be called several times.

The `FnOnce` bound allows new semantics: you can move out the upvars when the closure is called. This can be effectively paired with the `move || {}` syntax to transfer ownership from the environment to the closure caller.

In the case of trait methods, is hard to select the "right" bound since we can't control how the trait may be implemented by downstream users. In these cases, I have selected the bound based on how we use these traits in the repository. For this reason the selected bounds may not be ideal, and may require tweaking before stabilization.

r? @aturon
2014-12-13 22:57:21 +00:00
Jorge Aparicio
b8e0b81dd5 librustc_borrowck: add #![feature(unboxed_closures)] 2014-12-13 17:40:34 -05:00
Jorge Aparicio
db8300ce06 libstd: add missing imports 2014-12-13 17:03:48 -05:00
Jorge Aparicio
6f28816f87 Remove some unnecessary move keywords 2014-12-13 17:03:48 -05:00
Jorge Aparicio
745225d905 libtest: use unboxed closures 2014-12-13 17:03:48 -05:00
Jorge Aparicio
015c0fcee5 librustc_driver: use unboxed closures 2014-12-13 17:03:48 -05:00
Jorge Aparicio
521a6e62b1 librustc_typeck: use unboxed closures 2014-12-13 17:03:48 -05:00
Jorge Aparicio
888f24969f librustdoc: use unboxed closures 2014-12-13 17:03:48 -05:00
Jorge Aparicio
0676c3bf03 librustc_trans: use unboxed closures 2014-12-13 17:03:48 -05:00
Jorge Aparicio
0d4d8b9b78 librustc_trans: fix fallout 2014-12-13 17:03:47 -05:00
Jorge Aparicio
46272c18a2 librustc_typeck: fix fallout 2014-12-13 17:03:47 -05:00
Jorge Aparicio
1195708f64 librustc: use unboxed closures 2014-12-13 17:03:47 -05:00
Jorge Aparicio
933e7b4a3e librustc_llvm: use unboxed closures 2014-12-13 17:03:47 -05:00
Jorge Aparicio
3739a2427b librustc_trans: fix fallout 2014-12-13 17:03:47 -05:00
Jorge Aparicio
451eef5c40 librustc_back: use unboxed closures 2014-12-13 17:03:47 -05:00
Jorge Aparicio
d3d707c883 librustc: fix fallout 2014-12-13 17:03:47 -05:00
Jorge Aparicio
0dac05dd62 libsyntax: use unboxed closures 2014-12-13 17:03:47 -05:00
Jorge Aparicio
2160427900 Fix benches 2014-12-13 17:03:47 -05:00