Skip to content

Commit 87738fe

Browse files
committed
Switch existential_type to type_alias_impl_trait
1 parent 435236b commit 87738fe

File tree

7 files changed

+52
-61
lines changed

7 files changed

+52
-61
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ declare_features! (
453453
// Allows `#[doc(alias = "...")]`.
454454
(active, doc_alias, "1.27.0", Some(50146), None),
455455

456-
// Allows defining `existential type`s.
457-
(active, existential_type, "1.28.0", Some(63063), None),
458-
459456
// Allows inconsistent bounds in where clauses.
460457
(active, trivial_bounds, "1.28.0", Some(48214), None),
461458

@@ -560,6 +557,9 @@ declare_features! (
560557
// Allows `[x; N]` where `x` is a constant (RFC 2203).
561558
(active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None),
562559

560+
// Allows `impl Trait` to be used inside type aliases (RFC 2515).
561+
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),
562+
563563
// -------------------------------------------------------------------------
564564
// feature-group-end: actual feature gates
565565
// -------------------------------------------------------------------------
@@ -625,6 +625,9 @@ declare_features! (
625625
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
626626
(removed, await_macro, "1.38.0", Some(50547), None,
627627
Some("subsumed by `.await` syntax")),
628+
// Allows defining `existential type`s.
629+
(removed, existential_type, "1.38.0", Some(63063), None,
630+
Some("removed in favor of `#![feature(type_alias_impl_trait)]`")),
628631

629632
// -------------------------------------------------------------------------
630633
// feature-group-end: removed features
@@ -2017,7 +2020,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
20172020
ast::ItemKind::Existential(..) => {
20182021
gate_feature_post!(
20192022
&self,
2020-
existential_type,
2023+
type_alias_impl_trait,
20212024
i.span,
20222025
"existential types are unstable"
20232026
);
@@ -2246,7 +2249,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
22462249
ast::ImplItemKind::Existential(..) => {
22472250
gate_feature_post!(
22482251
&self,
2249-
existential_type,
2252+
type_alias_impl_trait,
22502253
ii.span,
22512254
"existential types are unstable"
22522255
);

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6805,40 +6805,29 @@ impl<'a> Parser<'a> {
68056805
Ok(self.mk_item(lo.to(prev_span), invalid, ItemKind::ForeignMod(m), visibility, attrs))
68066806
}
68076807

6808-
/// Parses `type Foo = Bar;`
6809-
/// or
6810-
/// `existential type Foo: Bar;`
6811-
/// or
6812-
/// `return `None``
6808+
/// Parses `type Foo = Bar;` or returns `None`
68136809
/// without modifying the parser state.
68146810
fn eat_type(&mut self) -> Option<PResult<'a, (Ident, AliasKind, ast::Generics)>> {
68156811
// This parses the grammar:
68166812
// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
6817-
if self.check_keyword(kw::Type) ||
6818-
self.check_keyword(kw::Existential) &&
6819-
self.is_keyword_ahead(1, &[kw::Type]) {
6820-
let existential = self.eat_keyword(kw::Existential);
6821-
assert!(self.eat_keyword(kw::Type));
6822-
Some(self.parse_existential_or_alias(existential))
6813+
if self.eat_keyword(kw::Type) {
6814+
Some(self.parse_type_alias())
68236815
} else {
68246816
None
68256817
}
68266818
}
68276819

68286820
/// Parses a type alias or existential type.
6829-
fn parse_existential_or_alias(
6830-
&mut self,
6831-
existential: bool,
6832-
) -> PResult<'a, (Ident, AliasKind, ast::Generics)> {
6821+
fn parse_type_alias(&mut self) -> PResult<'a, (Ident, AliasKind, ast::Generics)> {
68336822
let ident = self.parse_ident()?;
68346823
let mut tps = self.parse_generics()?;
68356824
tps.where_clause = self.parse_where_clause()?;
6836-
let alias = if existential {
6837-
self.expect(&token::Colon)?;
6825+
self.expect(&token::Eq)?;
6826+
let alias = if self.check_keyword(kw::Impl) {
6827+
self.bump();
68386828
let bounds = self.parse_generic_bounds(Some(self.prev_span))?;
68396829
AliasKind::Existential(bounds)
68406830
} else {
6841-
self.expect(&token::Eq)?;
68426831
let ty = self.parse_ty()?;
68436832
AliasKind::Weak(ty)
68446833
};

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ symbols! {
677677
tuple_indexing,
678678
Ty,
679679
ty,
680+
type_alias_impl_trait,
680681
TyCtxt,
681682
TyKind,
682683
type_alias_enum_variants,

src/test/ui/feature-gates/feature-gate-existential-type.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/test/ui/feature-gates/feature-gate-existential-type.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type Foo = impl std::fmt::Debug; //~ ERROR existential types are unstable
2+
3+
trait Bar {
4+
type Baa: std::fmt::Debug;
5+
fn define() -> Self::Baa;
6+
}
7+
8+
impl Bar for () {
9+
type Baa = impl std::fmt::Debug; //~ ERROR existential types are unstable
10+
fn define() -> Self::Baa { 0 }
11+
}
12+
13+
fn define() -> Foo { 0 }
14+
15+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0658]: existential types are unstable
2+
--> $DIR/feature-gate-type_alias_impl_trait.rs:1:1
3+
|
4+
LL | type Foo = impl std::fmt::Debug;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
8+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
9+
10+
error[E0658]: existential types are unstable
11+
--> $DIR/feature-gate-type_alias_impl_trait.rs:9:5
12+
|
13+
LL | type Baa = impl std::fmt::Debug;
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
17+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)