Commit Graph

35368 Commits

Author SHA1 Message Date
Luqman Aden
ab1bdde536 libsyntax: Output where clauses in pretty printer for structs. 2014-12-14 01:13:23 -05:00
Luqman Aden
ac7dc03a52 libsyntax: Make deriving also respect where bounds. 2014-12-14 01:13:23 -05:00
mchaput
f053f29ff5 Fix mispelling in char.rs error message
Error message has wrong spelling ("radix is to high").
2014-12-14 00:48:09 -05:00
Alex Crichton
7d1fa4ebea rustc: Start the deprecation of libserialize
The primary focus of Rust's stability story at 1.0 is the standard library.
All other libraries distributed with the Rust compiler are planned to
be #[unstable] and therfore only accessible on the nightly channel of Rust. One
of the more widely used libraries today is libserialize, Rust's current solution
for encoding and decoding types.

The current libserialize library, however, has a number of drawbacks:

* The API is not ready to be stabilize as-is and we will likely not have enough
  resources to stabilize the API for 1.0.
* The library is not necessarily the speediest implementations with alternatives
  being developed out-of-tree (e.g. serde from erickt).
* It is not clear how the API of Encodable/Decodable can evolve over time while
  maintaining backwards compatibility.

One of the major pros to the current libserialize, however, is
`deriving(Encodable, Decodable)` as short-hands for enabling serializing and
deserializing a type. This is unambiguously useful functionality, so we cannot
simply deprecate the in-tree libserialize in favor of an external crates.io
implementation.

For these reasons, this commit starts off a stability story for libserialize by
following these steps:

1. The deriving(Encodable, Decodable) modes will be deprecated in favor of a
   renamed deriving(RustcEncodable, RustcDecodable).
2. The in-tree libserialize will be deprecated in favor of an external
   rustc-serialize crate shipped on crates.io. The contents of the crate will be
   the same for now (but they can evolve separately).
3. At 1.0 serialization will be performed through
   deriving(RustcEncodable, RustcDecodable) and the rustc-serialize crate. The
   expansions for each deriving mode will change from `::serialize::foo` to
   `::rustc_serialize::foo`.

This story will require that the compiler freezes its implementation of
`RustcEncodable` deriving for all of time, but this should be a fairly minimal
maintenance burden. Otherwise the crate in crates.io must always maintain the
exact definition of its traits, but the implementation of json, for example, can
continue to evolve in the semver-sense.

The major goal for this stabilization effort is to pave the road for a new
official serialization crate which can replace the current one, solving many of
its downsides in the process. We are not assuming that this will exist for 1.0,
hence the above measures. Some possibilities for replacing libserialize include:

* If plugins have a stable API, then any crate can provide a custom `deriving`
  mode (will require some compiler work). This means that any new serialization
  crate can provide its own `deriving` with its own backing
  implementation, entirely obsoleting the current libserialize and fully
  replacing it.

* Erick is exploring the possibility of code generation via preprocessing Rust
  source files in the near term until plugins are stable. This strategy would
  provide the same ergonomic benefit that `deriving` does today in theory.

So, in summary, the current libserialize crate is being deprecated in favor of
the crates.io-based rustc-serialize crate where the `deriving` modes are
appropriately renamed. This opens up space for a later implementation of
serialization in a more official capacity while allowing alternative
implementations to be explored in the meantime.

Concretely speaking, this change adds support for the `RustcEncodable` and
`RustcDecodable` deriving modes. After a snapshot is made warnings will be
turned on for usage of `Encodable` and `Decodable` as well as deprecating the
in-tree libserialize crate to encurage users to use rustc-serialize instead.
2014-12-13 18:36:09 -08:00
Chase Southwood
81f9a31926 Change VecMap's iterators to use wrapper structs instead of typedefs.
Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.

This commit changes the iterators of `VecMap` to use
proper new types, rather than type aliases.  However, since it is
fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
2014-12-13 20:14:42 -06:00
Jorge Aparicio
89d2061c8f libcollections: convert BTreeSet binops to by value 2014-12-13 20:16:34 -05:00
Jorge Aparicio
e00e4611a8 libcollections: convert TreeSet binops to by value 2014-12-13 20:16:34 -05:00
Jorge Aparicio
308460400b libcollections: convert TrieSet binops to by value 2014-12-13 20:16:34 -05:00
Jorge Aparicio
dff2b395d2 Test binops move semantics 2014-12-13 20:16:34 -05:00
Jorge Aparicio
949b55e58e libcollections: add commutative version of Vec/String addition 2014-12-13 20:16:34 -05:00
Jorge Aparicio
f4abb12b0c Address Niko's comments 2014-12-13 20:16:34 -05:00
Jorge Aparicio
d193bf30ce libcore: fix doctests 2014-12-13 20:15:39 -05:00
Jorge Aparicio
bc23b8ebc6 libstd: fix unit tests 2014-12-13 20:15:39 -05:00
Jorge Aparicio
1ec5650ad3 libcoretest: fix unit tests 2014-12-13 20:15:39 -05:00
Jorge Aparicio
a672b27cbc libcollections: fix unit tests 2014-12-13 20:15:39 -05:00
Jorge Aparicio
f0b65674c3 Fix compile-fail tests 2014-12-13 20:15:39 -05:00
Jorge Aparicio
971add88d8 Fix run-pass tests 2014-12-13 20:15:39 -05:00
Jorge Aparicio
2b17083988 Test that binops consume their arguments 2014-12-13 20:15:39 -05:00
Jorge Aparicio
fb1d4f1b13 librustdoc: convert Counts binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
eb71976137 librustc: convert TypeContents binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
c4fa2a37ae libsyntax: convert LockstepIterSize binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
265b89abde libsyntax: convert BytePos/CharPos binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
b5537fa838 libtime: convert Timespec binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
9126a24e42 libstd: convert Duration binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
32168faf9f libstd: convert BitFlags binops to by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
baf79d4a11 libcollections: make EnumSet binops by value 2014-12-13 20:15:39 -05:00
Jorge Aparicio
076e932fd5 libcollections: String + &str 2014-12-13 20:15:39 -05:00
Jorge Aparicio
dbc7e17cce libcollections: Vec<T> + &[T] 2014-12-13 20:15:39 -05:00
Jorge Aparicio
65d3a40c07 libcore: fix move semantics fallout 2014-12-13 20:15:38 -05:00
Jorge Aparicio
c73259a269 libcore: convert binop traits to by value 2014-12-13 20:15:38 -05:00
Jorge Aparicio
227435a11e Tell regionck which binops are by value 2014-12-13 20:15:38 -05:00
Jorge Aparicio
5038f5a70c Tell expr_use_visitor which binops are by value 2014-12-13 20:15:38 -05:00
Jorge Aparicio
f64e52a7f7 Tell trans which binops are by value 2014-12-13 20:15:38 -05:00
Jorge Aparicio
c3a6d2860c Tell typeck which binops are by value 2014-12-13 20:15:38 -05:00
Jorge Aparicio
14c0a708cc syntax/ast_util: add is_by_value_binop() 2014-12-13 20:11:13 -05: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