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 associated type position impl Trait (ATPIT) #120700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 1 addition & 8 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -120,14 +120,7 @@ impl<'a> PostExpansionVisitor<'a> {
impl Visitor<'_> for ImplTraitVisitor<'_> {
fn visit_ty(&mut self, ty: &ast::Ty) {
if let ast::TyKind::ImplTrait(..) = ty.kind {
if self.in_associated_ty {
gate!(
&self.vis,
impl_trait_in_assoc_type,
ty.span,
"`impl Trait` in associated types is unstable"
);
} else {
if !self.in_associated_ty {
gate!(
&self.vis,
type_alias_impl_trait,
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(impl_trait_in_assoc_type)]
#![cfg_attr(bootstrap, feature(impl_trait_in_assoc_type))]

#[macro_use]
extern crate rustc_macros;
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
@@ -197,6 +197,8 @@ declare_features! (
/// + `impl<I:Iterator> Iterator for &mut Iterator`
/// + `impl Debug for Foo<'_>`
(accepted, impl_header_lifetime_elision, "1.31.0", Some(15872)),
/// Allows `impl Trait` to be used inside associated types (RFC 2515).
(accepted, impl_trait_in_assoc_type, "CURRENT_RUSTC_VERSION", Some(63063)),
/// Allows referencing `Self` and projections in impl-trait.
(accepted, impl_trait_projections, "1.74.0", Some(103532)),
/// Allows using `a..=b` and `..=b` as inclusive range syntaxes.
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
@@ -483,8 +483,6 @@ declare_features! (
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
/// Allows `if let` guard in match arms.
(unstable, if_let_guard, "1.47.0", Some(51114)),
/// Allows `impl Trait` to be used inside associated types (RFC 2515).
(unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)),
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.
(unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)),
/// Allows using imported `main` function
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#![feature(const_type_name)]
#![feature(cow_is_borrowed)]
#![feature(decl_macro)]
#![feature(impl_trait_in_assoc_type)]
#![cfg_attr(bootstrap, feature(impl_trait_in_assoc_type))]
#![feature(inline_const)]
#![feature(is_sorted)]
#![feature(let_chains)]
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(impl_trait_in_assoc_type)]
#![cfg_attr(bootstrap, feature(impl_trait_in_assoc_type))]
#![feature(iter_intersperse)]
#![feature(lazy_cell)]
#![feature(let_chains)]
2 changes: 0 additions & 2 deletions tests/rustdoc/auxiliary/issue-73061.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//edition:2018

#![feature(impl_trait_in_assoc_type)]

pub trait Foo {
type X: std::future::Future<Output = ()>;
fn x(&self) -> Self::X;
1 change: 0 additions & 1 deletion tests/ui/associated-types/issue-63591.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// check-pass

#![feature(associated_type_bounds)]
#![feature(impl_trait_in_assoc_type)]

fn main() {}

2 changes: 1 addition & 1 deletion tests/ui/coroutine/issue-87142.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
// Regression test for #87142
// This test needs the above flags and the "lib" crate type.

#![feature(impl_trait_in_assoc_type, coroutine_trait, coroutines)]
#![feature(coroutine_trait, coroutines)]
#![crate_type = "lib"]

use std::ops::Coroutine;
20 changes: 0 additions & 20 deletions tests/ui/feature-gates/feature-gate-impl_trait_in_assoc_type.rs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions tests/ui/generic-associated-types/issue-86218-2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// check-pass

#![feature(impl_trait_in_assoc_type)]

pub trait Stream {
type Item;
}
2 changes: 0 additions & 2 deletions tests/ui/generic-associated-types/issue-86218.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// check-pass

#![feature(impl_trait_in_assoc_type)]

pub trait Stream {
type Item;
}
2 changes: 0 additions & 2 deletions tests/ui/generic-associated-types/issue-87258_a.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(impl_trait_in_assoc_type)]

// See https://github.com/rust-lang/rust/issues/87258#issuecomment-883293367

trait Trait1 {}
2 changes: 1 addition & 1 deletion tests/ui/generic-associated-types/issue-87258_a.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: unconstrained opaque type
--> $DIR/issue-87258_a.rs:17:26
--> $DIR/issue-87258_a.rs:15:26
|
LL | type FooFuture<'a> = impl Trait1;
| ^^^^^^^^^^^
2 changes: 0 additions & 2 deletions tests/ui/generic-associated-types/issue-88595.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(impl_trait_in_assoc_type)]

fn main() {}

#[rustfmt::skip]
4 changes: 2 additions & 2 deletions tests/ui/generic-associated-types/issue-88595.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: non-defining opaque type use in defining scope
--> $DIR/issue-88595.rs:21:23
--> $DIR/issue-88595.rs:19:23
|
LL | fn a(&'a self) -> Self::B<'a> {}
| ^^^^^^^^^^^ generic argument `'a` used twice
|
note: for this opaque type
--> $DIR/issue-88595.rs:19:18
--> $DIR/issue-88595.rs:17:18
|
LL | type B<'b> = impl Clone;
| ^^^^^^^^^^
2 changes: 0 additions & 2 deletions tests/ui/generic-associated-types/issue-89008.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// check-pass
// edition:2021

#![feature(impl_trait_in_assoc_type)]

use std::future::Future;
use std::marker::PhantomData;

2 changes: 1 addition & 1 deletion tests/ui/generic-associated-types/issue-90014-tait.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
// known-bug: unknown
// edition:2018

#![feature(impl_trait_in_assoc_type, inherent_associated_types)]
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

use std::future::Future;
2 changes: 0 additions & 2 deletions tests/ui/generic-associated-types/issue-90014.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// edition:2018

#![feature(impl_trait_in_assoc_type)]

use std::future::Future;

trait MakeFut {
4 changes: 2 additions & 2 deletions tests/ui/generic-associated-types/issue-90014.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0477]: the type `&mut ()` does not fulfill the required lifetime
--> $DIR/issue-90014.rs:15:20
--> $DIR/issue-90014.rs:13:20
|
LL | type Fut<'a>
| ------------ definition of `Fut` from trait
@@ -8,7 +8,7 @@ LL | type Fut<'a> = impl Future<Output = ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: type must outlive the lifetime `'a` as defined here
--> $DIR/issue-90014.rs:15:14
--> $DIR/issue-90014.rs:13:14
|
LL | type Fut<'a> = impl Future<Output = ()>;
| ^^
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(impl_trait_in_assoc_type)]
// build-pass (FIXME(62277): could be check-pass?)

trait Bar {}
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@
// edition: 2021
// build-pass: ICEd during codegen.

#![feature(impl_trait_in_assoc_type)]

use std::future::Future;

fn main() {
1 change: 0 additions & 1 deletion tests/ui/impl-trait/associated-impl-trait-type-trivial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(impl_trait_in_assoc_type)]
// build-pass (FIXME(62277): could be check-pass?)

trait Bar {}
1 change: 0 additions & 1 deletion tests/ui/impl-trait/associated-impl-trait-type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(impl_trait_in_assoc_type)]
// build-pass (FIXME(62277): could be check-pass?)

trait Bar {}
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/in-assoc-type-unconstrained.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(impl_trait_in_assoc_type)]

mod compare_ty {
trait Trait {
type Ty: IntoIterator<Item = ()>;
14 changes: 7 additions & 7 deletions tests/ui/impl-trait/in-assoc-type-unconstrained.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
error[E0271]: type mismatch resolving `<Option<<() as Trait>::Ty::{opaque#0}> as IntoIterator>::Item == ()`
--> $DIR/in-assoc-type-unconstrained.rs:8:19
--> $DIR/in-assoc-type-unconstrained.rs:6:19
|
LL | type Ty = Option<impl Sized>;
| ^^^^^^^^^^^^^^^^^^ expected `()`, found opaque type
|
= note: expected unit type `()`
found opaque type `<() as compare_ty::Trait>::Ty::{opaque#0}`
note: required by a bound in `compare_ty::Trait::Ty`
--> $DIR/in-assoc-type-unconstrained.rs:5:31
--> $DIR/in-assoc-type-unconstrained.rs:3:31
|
LL | type Ty: IntoIterator<Item = ()>;
| ^^^^^^^^^ required by this bound in `Trait::Ty`

error: unconstrained opaque type
--> $DIR/in-assoc-type-unconstrained.rs:8:26
--> $DIR/in-assoc-type-unconstrained.rs:6:26
|
LL | type Ty = Option<impl Sized>;
| ^^^^^^^^^^
|
= note: `Ty` must be used in combination with a concrete type within the same impl

error[E0053]: method `method` has an incompatible type for trait
--> $DIR/in-assoc-type-unconstrained.rs:22:24
--> $DIR/in-assoc-type-unconstrained.rs:20:24
|
LL | type Ty = impl Sized;
| ---------- the expected opaque type
@@ -33,20 +33,20 @@ LL | fn method() -> () {}
| help: change the output type to match the trait: `<() as compare_method::Trait>::Ty`
|
note: type in trait
--> $DIR/in-assoc-type-unconstrained.rs:17:24
--> $DIR/in-assoc-type-unconstrained.rs:15:24
|
LL | fn method() -> Self::Ty;
| ^^^^^^^^
= note: expected signature `fn() -> <() as compare_method::Trait>::Ty`
found signature `fn()`
note: this item must have the opaque type in its signature in order to be able to register hidden types
--> $DIR/in-assoc-type-unconstrained.rs:22:12
--> $DIR/in-assoc-type-unconstrained.rs:20:12
|
LL | fn method() -> () {}
| ^^^^^^

error: unconstrained opaque type
--> $DIR/in-assoc-type-unconstrained.rs:20:19
--> $DIR/in-assoc-type-unconstrained.rs:18:19
|
LL | type Ty = impl Sized;
| ^^^^^^^^^^
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/in-assoc-type.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! This test checks that we don't allow registering hidden types for
//! opaque types from other impls.

#![feature(impl_trait_in_assoc_type)]

trait Foo<T> {
type Bar;
fn foo(&self) -> <Self as Foo<()>>::Bar
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/in-assoc-type.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/in-assoc-type.rs:20:22
--> $DIR/in-assoc-type.rs:18:22
|
LL | type Bar = impl std::fmt::Debug;
| -------------------- the expected opaque type
@@ -12,7 +12,7 @@ LL | fn foo(&self) -> <Self as Foo<()>>::Bar {}
= note: expected opaque type `<() as Foo<()>>::Bar`
found unit type `()`
note: this item must have the opaque type in its signature in order to be able to register hidden types
--> $DIR/in-assoc-type.rs:20:8
--> $DIR/in-assoc-type.rs:18:8
|
LL | fn foo(&self) -> <Self as Foo<()>>::Bar {}
| ^^^
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/issue-55872-1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(impl_trait_in_assoc_type)]

pub trait Bar {
type E: Copy;

6 changes: 3 additions & 3 deletions tests/ui/impl-trait/issue-55872-1.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0276]: impl has stricter requirements than trait
--> $DIR/issue-55872-1.rs:12:15
--> $DIR/issue-55872-1.rs:10:15
|
LL | fn foo<T>() -> Self::E;
| ----------------------- definition of `foo` from trait
@@ -8,7 +8,7 @@ LL | fn foo<T: Default>() -> Self::E {
| ^^^^^^^ impl has extra requirement `T: Default`

error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
--> $DIR/issue-55872-1.rs:12:29
--> $DIR/issue-55872-1.rs:10:29
|
LL | fn foo<T: Default>() -> Self::E {
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`, which is required by `(S, T): Copy`
@@ -20,7 +20,7 @@ LL | impl<S: Default + std::marker::Copy> Bar for S {
| +++++++++++++++++++

error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
--> $DIR/issue-55872-1.rs:12:29
--> $DIR/issue-55872-1.rs:10:29
|
LL | fn foo<T: Default>() -> Self::E {
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`, which is required by `(S, T): Copy`
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/issue-55872-2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// edition:2018

#![feature(impl_trait_in_assoc_type)]

pub trait Bar {
type E: Send;

Loading