rust/src
bors f55ac6944a Auto merge of #35091 - eddyb:impl-trait, r=nikomatsakis
Implement `impl Trait` in return type position by anonymization.

This is the first step towards implementing `impl Trait` (cc #34511).
`impl Trait` types are only allowed in function and inherent method return types, and capture all named lifetime and type parameters, being invariant over them.
No lifetimes that are not explicitly named lifetime parameters are allowed to escape from the function body.
The exposed traits are only those listed explicitly, i.e. `Foo` and `Clone` in `impl Foo + Clone`, with the exception of "auto traits" (like `Send` or `Sync`) which "leak" the actual contents.

The implementation strategy is anonymization, i.e.:
```rust
fn foo<T>(xs: Vec<T>) -> impl Iterator<Item=impl FnOnce() -> T> {
    xs.into_iter().map(|x| || x)
}

// is represented as:
type A</*invariant over*/ T> where A<T>: Iterator<Item=B<T>>;
type B</*invariant over*/ T> where B<T>: FnOnce() -> T;
fn foo<T>(xs: Vec<T>) -> A<T> {
    xs.into_iter().map(|x| || x): $0 where $0: Iterator<Item=$1>, $1: FnOnce() -> T
}
```
`$0` and `$1` are resolved (to `iter::Map<vec::Iter<T>, closure>` and the closure, respectively) and assigned to `A` and `B`, after checking the body of `foo`. `A` and `B` are *never* resolved for user-facing type equality (typeck), but always for the low-level representation and specialization (trans).

The "auto traits" exception is implemented by collecting bounds like `impl Trait: Send` that have failed for the obscure `impl Trait` type (i.e. `A` or `B` above), pretending they succeeded within the function and trying them again after type-checking the whole crate, by replacing `impl Trait` with the real type.

While passing around values which have explicit lifetime parameters (of the function with `-> impl Trait`) in their type *should* work, regionck appears to assign inference variables in *way* too many cases, and never properly resolving them to either explicit lifetime parameters, or `'static`.
We might not be able to handle lifetime parameters in `impl Trait` without changes to lifetime inference, but type parameters can have arbitrary lifetimes in them from the caller, so most type-generic usecases (or not generic at all) should not run into this problem.

cc @rust-lang/lang
2016-08-12 01:26:12 -07:00
..
bootstrap Improved checking of target's llvm_config 2016-08-10 22:24:51 +10:00
build_helper
compiler-rt@8598065bd9
doc Rollup merge of #35466 - xitep:master, r=steveklabnik 2016-08-08 13:25:57 -07:00
driver
etc
grammar
jemalloc@e058ca6616
liballoc
liballoc_jemalloc
liballoc_system
libarena
libbacktrace
libcollections Add tracking issue for String::insert_str 2016-08-09 11:42:16 -07:00
libcollectionstest
libcore Rollup merge of #35562 - birkenfeld:as-mut-doc, r=steveklabnik 2016-08-11 06:34:01 -07:00
libcoretest
libflate
libfmt_macros
libgetopts
libgraphviz
liblibc@5066b7dcab
liblog
libpanic_abort
libpanic_unwind
librand
librbml
librustc typeck: leak auto trait obligations through impl Trait. 2016-08-12 06:46:31 +03:00
librustc_back
librustc_bitflags
librustc_borrowck Auto merge of #35592 - jonathandturner:rollup, r=jonathandturner 2016-08-11 13:14:28 -07:00
librustc_const_eval rustc: rename ProjectionMode and its variant to be more memorable. 2016-08-12 06:43:34 +03:00
librustc_const_math
librustc_data_structures generalize BitMatrix to be NxM and not just NxN 2016-08-09 08:26:06 -04:00
librustc_driver Auto merge of #35091 - eddyb:impl-trait, r=nikomatsakis 2016-08-12 01:26:12 -07:00
librustc_errors
librustc_incremental pacify the merciless tidy 2016-08-09 20:28:46 -04:00
librustc_lint rustc: add TyAnon (impl Trait) to the typesystem. 2016-08-12 06:43:34 +03:00
librustc_llvm
librustc_metadata typeck: record impl Trait concrete resolutions. 2016-08-12 06:43:34 +03:00
librustc_mir rustc: rename ProjectionMode and its variant to be more memorable. 2016-08-12 06:43:34 +03:00
librustc_passes rustc: rename ProjectionMode and its variant to be more memorable. 2016-08-12 06:43:34 +03:00
librustc_platform_intrinsics
librustc_plugin
librustc_privacy privacy: Move private-in-public diagnostics for type aliases to the public interface location 2016-08-11 00:32:07 +03:00
librustc_resolve Auto merge of #35592 - jonathandturner:rollup, r=jonathandturner 2016-08-11 13:14:28 -07:00
librustc_save_analysis
librustc_trans rustc: add TyAnon (impl Trait) to the typesystem. 2016-08-12 06:43:34 +03:00
librustc_typeck typeck: leak auto trait obligations through impl Trait. 2016-08-12 06:46:31 +03:00
librustc_unicode
librustdoc rustc: add TyAnon (impl Trait) to the typesystem. 2016-08-12 06:43:34 +03:00
libserialize
libstd Rollup merge of #35569 - pietroalbini:fix-typo, r=steveklabnik 2016-08-11 06:34:02 -07:00
libsyntax Auto merge of #35091 - eddyb:impl-trait, r=nikomatsakis 2016-08-12 01:26:12 -07:00
libsyntax_ext
libsyntax_pos
libterm
libtest
libunwind
llvm@786aad117b Improved checking of target's llvm_config 2016-08-10 22:24:51 +10:00
rt
rtstartup
rust-installer@c37d3747da
rustc
rustllvm Improved checking of target's llvm_config 2016-08-10 22:24:51 +10:00
test test: add more extensive tests for impl Trait. 2016-08-12 06:46:31 +03:00
tools Rollup merge of #35448 - srinivasreddy:rf_compiletest, r=nikomatsakis 2016-08-11 06:33:58 -07:00
stage0.txt