rust/src/librustc_typeck
bors 59183180f7 Auto merge of #56225 - alexreg:type_alias_enum_variants, r=petrochenkov
Implement RFC 2338, "Type alias enum variants"

This PR implements [RFC 2338](https://github.com/rust-lang/rfcs/pull/2338), allowing one to write code like the following.

```rust
#![feature(type_alias_enum_variants)]

enum Foo {
    Bar(i32),
    Baz { i: i32 },
}

type Alias = Foo;

fn main() {
    let t = Alias::Bar(0);
    let t = Alias::Baz { i: 0 };
    match t {
        Alias::Bar(_i) => {}
        Alias::Baz { i: _i } => {}
    }
}
```

Since `Self` can be considered a type alias in this context, it also enables using `Self::Variant` as both a constructor and pattern.

Fixes issues #56199 and #56611.

N.B., after discussing the syntax for type arguments on enum variants with @petrochenkov and @eddyb (there are also a few comments on the [tracking issue](https://github.com/rust-lang/rust/issues/49683)), the consensus seems to be treat the syntax as follows, which ought to be backwards-compatible.

```rust
Option::<u8>::None; // OK
Option::None::<u8>; // OK, but lint in near future (hard error next edition?)
Alias::<u8>::None; // OK
Alias::None::<u8>; // Error
```

I do not know if this will need an FCP, but let's start one if so.
2018-12-29 21:03:11 +00:00
..
check Auto merge of #56225 - alexreg:type_alias_enum_variants, r=petrochenkov 2018-12-29 21:03:11 +00:00
coherence Remove licenses 2018-12-25 21:08:33 -07:00
outlives Remove licenses 2018-12-25 21:08:33 -07:00
variance Remove licenses 2018-12-25 21:08:33 -07:00
astconv.rs Changed resolution of enum variants to low priority. 2018-12-26 21:56:47 +00:00
Cargo.toml Upgrade smallvec to 0.6.7 and use the new may_dangle feature. 2018-12-10 09:31:27 +11:00
check_unused.rs Store Ident rather than just Name in HIR types Item and ForeignItem. 2018-12-26 21:26:37 +00:00
collect.rs Auto merge of #56225 - alexreg:type_alias_enum_variants, r=petrochenkov 2018-12-29 21:03:11 +00:00
constrained_type_params.rs Remove licenses 2018-12-25 21:08:33 -07:00
diagnostics.rs Added regression test for using generic parameters on modules. 2018-12-26 21:54:18 +00:00
impl_wf_check.rs Remove licenses 2018-12-25 21:08:33 -07:00
lib.rs Fixed issues raised in first review. 2018-12-26 21:40:21 +00:00
namespace.rs Remove licenses 2018-12-25 21:08:33 -07:00
README.md rustc-guide has moved 2018-11-26 15:03:13 -06:00
structured_errors.rs Remove licenses 2018-12-25 21:08:33 -07:00

For high-level intro to how type checking works in rustc, see the type checking chapter of the rustc guide.