Commit Graph

55740 Commits

Author SHA1 Message Date
Andrew Cann
bcff5a78b3 Permit ! as T with test 2016-08-13 21:37:09 +08:00
Andrew Cann
06747c669f Add another test for ! 2016-08-13 21:37:09 +08:00
Andrew Cann
00a71ea644 Add tests for ! type 2016-08-13 21:37:09 +08:00
Andrew Cann
2eff282aef Add some tests for ! type 2016-08-13 21:37:09 +08:00
Andrew Cann
c6890e17a0 Revert Ty::is_uninhabited to its original state 2016-08-13 21:37:09 +08:00
Andrew Cann
a4e6009bf0 Minor fixups based on feedback 2016-08-13 21:37:09 +08:00
Andrew Cann
a05560bebe Add run-pass/never_coercions.rs test 2016-08-13 21:37:09 +08:00
Andrew Cann
f019a92b77 Correctly handle AdjustNeverToAny in try_find_coercion_lub 2016-08-13 21:37:09 +08:00
Andrew Cann
69e27614c6 Minor fixup. 2016-08-13 21:37:09 +08:00
Andrew Cann
a6d6fff068 Lookup node type in map rather than using write_ty_expr 2016-08-13 21:37:09 +08:00
Andrew Cann
3639341685 Default diverging types based on feature gate.
Default to either `!` or `()` depending on whether feature(never_type)
is on or not.
2016-08-13 21:37:09 +08:00
Andrew Cann
54c72d8f98 Minor fix 2016-08-13 21:37:09 +08:00
Andrew Cann
8010314190 Un-improve Ty::is_uninabited 2016-08-13 21:37:09 +08:00
Andrew Cann
fadabe08f5 Rename empty/bang to never
Split Ty::is_empty method into is_never and is_uninhabited
2016-08-13 21:37:09 +08:00
Andrew Cann
f0a8b6d43f Minor fixups based on @eddyb's feedback
Mainly, remove mk_empty() method and replace with tcx.types.empty
2016-08-13 21:37:09 +08:00
Andrew Cann
5096a8c5c0 Control usage of ! through a feature gate.
Adds the `bang_type` feature gate. `!` in a non-return-type position now
relies on that feature.
2016-08-13 21:37:09 +08:00
Andrew Cann
0e1c2aa52e Make AdjustEmptyToAny actually perform the adjustment 2016-08-13 21:37:09 +08:00
Andrew Cann
ba65d2e15b Remove invalid compile-fail tests related to !
These tests check for the old error messages "`return` in a function
declared as diverging" and "computation may converge in a function
declared as diverging". The first of these is now invalid as `return` is
permitted in functions that return `!`. The second of these is subsumed
by the "mismatched types" error.
2016-08-13 21:37:09 +08:00
Andrew Cann
51c6ae25e2 implement std::cmp::* traits for ! 2016-08-13 21:37:09 +08:00
Andrew Cann
b22beed737 Fix build after rebase to lastest master 2016-08-13 21:37:09 +08:00
Andrew Cann
ed02344fbc Remove obsolete divergence related stuff
Replace FnOutput with Ty
Replace FnConverging(ty) with ty
Purge FnDiverging, FunctionRetTy::NoReturn and FunctionRetTy::None
2016-08-13 21:37:09 +08:00
Andrew Cann
ee78f37e2a impl Debug + Display for ! 2016-08-13 21:37:09 +08:00
Andrew Cann
082915290d Make unused lint ignore unused ! 2016-08-13 21:37:09 +08:00
Andrew Cann
f31d9757f8 Fix super_relate_tys so that ! == ! 2016-08-13 21:37:09 +08:00
Andrew Cann
104963c539 Switch on TyEmpty
Parse -> ! as FnConverging(!)
Add AdjustEmptyToAny coercion to all ! expressions
Some fixes
2016-08-13 21:37:09 +08:00
Andrew Cann
9f9f8567eb Fix rustdoc after rebase 2016-08-13 21:37:09 +08:00
Andrew Cann
533a389962 Small optimization
Optimiize ExprKind::EmptyToAny expressions applied to function calls.
2016-08-13 21:37:09 +08:00
Andrew Cann
798f719daf Add run-fail/adjust_empty.rs test 2016-08-13 21:37:09 +08:00
Andrew Cann
c88c54ec5a Invoke coercions on ! 2016-08-13 21:37:09 +08:00
Andrew Cann
0d863616e0 Add EmptyToAny adjustment 2016-08-13 21:37:09 +08:00
Andrew Cann
b0a9acd783 Parse ! as TyEmpty (except in fn return type) 2016-08-13 21:37:09 +08:00
Andrew Cann
ba7330c1cc Start implementation of RFC 1216 (make ! a type)
Add `TyKind::Empty` and fix resulting build errors.
2016-08-13 21:37:09 +08:00
bors
e64f68817d Auto merge of #35348 - scottcarr:discriminant2, r=nikomatsakis
[MIR] Add explicit SetDiscriminant StatementKind for deaggregating enums

cc #35186

To deaggregate enums, we need to be able to explicitly set the discriminant.  This PR implements a new StatementKind that does that.

I think some of the places that have `panics!` now could maybe do something smarter.
2016-08-13 01:20:46 -07:00
bors
d3c3de8abe Auto merge of #35138 - petrochenkov:clarify, r=eddyb
Implement RFC 1506 "Clarify the relationships between various kinds of structs and variants"

cc https://github.com/rust-lang/rust/issues/35626
2016-08-12 19:38:46 -07:00
Vadim Petrochenkov
f6624782d4 Parse numeric fields in struct expressions and patterns 2016-08-13 00:08:14 +03:00
Vadim Petrochenkov
59be332a1b Remove restrictions from tuple structs/variants
Hard errors are turned into feature gates
2016-08-13 00:08:14 +03:00
bors
1deb02ea69 Auto merge of #35431 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes

r? @jonathandturner
2016-08-12 08:58:55 -07:00
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
bors
68d9284a9b Auto merge of #34811 - DanielJCampbell:Expander, r=jseyfried
Extended expand.rs to support alternate expansion behaviours (eg. stepwise expansion)

r? nrc
2016-08-11 22:10:16 -07:00
Eduard Burtescu
23f0494114 test: add more extensive tests for impl Trait. 2016-08-12 06:46:31 +03:00
Eduard Burtescu
08bf9f69b9 typeck: leak auto trait obligations through impl Trait. 2016-08-12 06:46:31 +03:00
Eduard Burtescu
d92e594c38 typeck: record impl Trait concrete resolutions. 2016-08-12 06:43:34 +03:00
Eduard Burtescu
1ef7ddfda3 typeck: disallow impl Trait outside of return types of functions and impl methods. 2016-08-12 06:43:34 +03:00
Eduard Burtescu
ef11d4e3c7 rustc: add TyAnon (impl Trait) to the typesystem. 2016-08-12 06:43:34 +03:00
Eduard Burtescu
f0baec691f syntax: add anonymized type syntax, i.e. impl TraitA+TraitB. 2016-08-12 06:43:34 +03:00
Eduard Burtescu
c976e073fd rustc: don't reveal specializable polymorphic projections. 2016-08-12 06:43:34 +03:00
Eduard Burtescu
ab26dbb96f rustc: always normalize projections in ty::layout regardless where they appear. 2016-08-12 06:43:34 +03:00
Eduard Burtescu
d1d16c94c5 rustc: rename ProjectionMode and its variant to be more memorable. 2016-08-12 06:43:34 +03:00
bors
8787a12334 Auto merge of #35592 - jonathandturner:rollup, r=jonathandturner
Rollup of 23 pull requests

- Successful merges: #35279, #35331, #35358, #35375, #35445, #35448, #35482, #35486, #35505, #35528, #35530, #35532, #35536, #35537, #35541, #35552, #35554, #35555, #35557, #35562, #35565, #35569, #35576
- Failed merges: #35395, #35415, #35563
2016-08-11 13:14:28 -07:00
Scott A Carr
d77a136437 add SetDiscriminant StatementKind to enable deaggregation of enums 2016-08-11 11:51:20 -07:00