Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize generic associated types #96709

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,25 +342,6 @@ impl<'a> PostExpansionVisitor<'a> {
}
}

fn check_gat(&self, generics: &ast::Generics, span: Span) {
if !generics.params.is_empty() {
gate_feature_post!(
&self,
generic_associated_types,
span,
"generic associated types are unstable"
);
}
if !generics.where_clause.predicates.is_empty() {
gate_feature_post!(
&self,
generic_associated_types,
span,
"where clauses on associated types are unstable"
);
}
}

/// Feature gate `impl Trait` inside `type Alias = $type_expr;`.
fn check_impl_trait(&self, ty: &ast::Ty) {
struct ImplTraitVisitor<'a> {
Expand Down Expand Up @@ -719,7 +700,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
let is_fn = match i.kind {
ast::AssocItemKind::Fn(_) => true,
ast::AssocItemKind::TyAlias(box ast::TyAlias { ref generics, ref ty, .. }) => {
ast::AssocItemKind::TyAlias(box ast::TyAlias { ref ty, .. }) => {
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
gate_feature_post!(
&self,
Expand All @@ -731,7 +712,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
if let Some(ty) = ty {
self.check_impl_trait(ty);
}
self.check_gat(generics, i.span);
false
}
_ => false,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ declare_features! (
(accepted, fn_must_use, "1.27.0", Some(43302), None),
/// Allows capturing variables in scope using format_args!
(accepted, format_args_capture, "1.58.0", Some(67984), None),
/// Allows associated types to be generic, e.g., `type Foo<T>;` (RFC 1598).
(accepted, generic_associated_types, "CURRENT_RUSTC_VERSION", Some(44265), None),
/// Allows attributes on lifetime/type formal parameters in generics (RFC 1327).
(accepted, generic_param_attrs, "1.27.0", Some(48848), None),
/// Allows the `#[global_allocator]` attribute.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ declare_features! (
(active, generators, "1.21.0", Some(43122), None),
/// Infer generic args for both consts and types.
(active, generic_arg_infer, "1.55.0", Some(85077), None),
/// Allows associated types to be generic, e.g., `type Foo<T>;` (RFC 1598).
(active, generic_associated_types, "1.23.0", Some(44265), None),
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
(incomplete, generic_associated_types_extended, "1.61.0", Some(95451), None),
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3989,8 +3989,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(generic_associated_types)]
///
/// trait Trait {
/// type Assoc<'a> where Self: 'a;
/// }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(decl_macro)]
#![feature(drain_filter)]
#![feature(generators)]
#![feature(generic_associated_types)]
#![cfg_attr(bootstrap, feature(generic_associated_types))]
#![feature(iter_from_generator)]
#![feature(let_chains)]
#![feature(let_else)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#![feature(discriminant_kind)]
#![feature(exhaustive_patterns)]
#![feature(get_mut_unchecked)]
#![feature(generic_associated_types)]
#![cfg_attr(bootstrap, feature(generic_associated_types))]
#![feature(if_let_guard)]
#![feature(map_first_last)]
#![feature(negative_impls)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2064,8 +2064,6 @@ fn confirm_impl_candidate<'cx, 'tcx>(

// Get obligations corresponding to the predicates from the where-clause of the
// associated type itself.
// Note: `feature(generic_associated_types)` is required to write such
// predicates, even for non-generic associated types.
fn assoc_ty_own_obligations<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#![feature(type_ascription)]
#![feature(iter_intersperse)]
#![feature(type_alias_impl_trait)]
#![feature(generic_associated_types)]
#![cfg_attr(bootstrap, feature(generic_associated_types))]
#![recursion_limit = "256"]
#![warn(rustc::internal)]
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
Expand Down
2 changes: 0 additions & 2 deletions src/test/pretty/gat-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// pretty-compare-only

#![feature(generic_associated_types)]

trait X {
type Y<T>: Trait where Self: Sized;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-json/generic-associated-types/gats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore-tidy-linelength

#![no_core]
#![feature(generic_associated_types, lang_items, no_core)]
#![feature(lang_items, no_core)]

#[lang = "sized"]
pub trait Sized {}
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/generic-associated-types/gats.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_name = "foo"]
#![feature(generic_associated_types)]

// @has foo/trait.LendingIterator.html
pub trait LendingIterator {
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/generic-associated-types/issue-94683.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_name = "foo"]
#![feature(generic_associated_types)]

pub trait Trait {
type Gat<'a>;
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/where.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(generic_associated_types)]
#![crate_name = "foo"]

pub trait MyTrait { fn dummy(&self) { } }
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/associated-type-bounds/binder-on-bound.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(generic_associated_types)]

trait Trait {
type Bound<'a>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-type-bounds/binder-on-bound.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `for<...>` is not allowed on associated type bounds
--> $DIR/binder-on-bound.rs:7:22
--> $DIR/binder-on-bound.rs:5:22
|
LL | fn foo() where Trait<for<'a> Bound<'a> = &'a ()> {
| ^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/associated-type-bounds/issue-79949.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![allow(incomplete_features)]
#![feature(associated_type_bounds)]
#![feature(generic_associated_types)]

trait MP {
type T<'a>;
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/deriving/issue-89188-gat-hrtb.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// check-pass

#![feature(generic_associated_types)]

trait CallWithShim: Sized {
type Shim<'s>
where
Expand Down
31 changes: 0 additions & 31 deletions src/test/ui/feature-gates/feature-gate-generic_associated_types.rs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(generic_associated_types)]

// This feature doesn't *currently* fire on any specific code; it's just a
// behavior change. Future changes might.
#[rustc_error] //~ the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: the `#[rustc_error]` attribute is just used for rustc unit tests and will never be stable
--> $DIR/feature-gate-generic_associated_types_extended.rs:5:1
--> $DIR/feature-gate-generic_associated_types_extended.rs:3:1
|
LL | #[rustc_error]
| ^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// check-pass
//
// regression test for #98702
#![feature(generic_associated_types)]

trait Foo {
type Assoc<T>;
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/generic-associated-types/auxiliary/foo_defn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(generic_associated_types)]

use std::{future::Future, pin::Pin};

pub trait Foo {
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/generic-associated-types/bugs/issue-80626.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// This should pass, but it requires `Sized` to be coinductive.

#![feature(generic_associated_types)]

trait Allocator {
type Allocated<T>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/generic-associated-types/bugs/issue-80626.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0275]: overflow evaluating the requirement `LinkedList<A>: Sized`
--> $DIR/issue-80626.rs:14:10
--> $DIR/issue-80626.rs:12:10
|
LL | Next(A::Allocated<Self>)
| ^^^^^^^^^^^^^^^^^^
|
note: required by a bound in `Allocator::Allocated`
--> $DIR/issue-80626.rs:9:20
--> $DIR/issue-80626.rs:7:20
|
LL | type Allocated<T>;
| ^ required by this bound in `Allocator::Allocated`
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/generic-associated-types/bugs/issue-86218.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

// This should pass, but seems to run into a TAIT issue.

#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

pub trait Stream {
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/generic-associated-types/bugs/issue-86218.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0477]: the type `<() as Yay<&'a ()>>::InnerStream<'s>` does not fulfill the required lifetime
--> $DIR/issue-86218.rs:23:28
--> $DIR/issue-86218.rs:22:28
|
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: type must outlive the lifetime `'s` as defined here as required by this binding
--> $DIR/issue-86218.rs:23:22
--> $DIR/issue-86218.rs:22:22
|
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
| ^^

error: unconstrained opaque type
--> $DIR/issue-86218.rs:23:28
--> $DIR/issue-86218.rs:22:28
|
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/generic-associated-types/bugs/issue-87735.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// This should pass, but we need an extension of implied bounds (probably).

#![feature(generic_associated_types)]

pub trait AsRef2 {
type Output<'a> where Self: 'a;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-87735.rs:27:13
--> $DIR/issue-87735.rs:25:13
|
LL | impl<'b, T, U> AsRef2 for Foo<T>
| ^ unconstrained type parameter
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/generic-associated-types/bugs/issue-87755.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// This should pass.

#![feature(generic_associated_types)]

use std::fmt::Debug;

trait Foo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0275]: overflow evaluating the requirement `<Bar as Foo>::Ass == _`
--> $DIR/issue-87755.rs:18:16
--> $DIR/issue-87755.rs:16:16
|
LL | type Ass = Bar;
| ^^^
Expand Down
Loading