Skip to content

Commit

Permalink
Stabilize associated type position impl Trait (ATPIT)
Browse files Browse the repository at this point in the history
  • Loading branch information
traviscross committed Feb 6, 2024
1 parent f3b9d47 commit a47c353
Show file tree
Hide file tree
Showing 131 changed files with 128 additions and 349 deletions.
9 changes: 1 addition & 8 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

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 @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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)]
Expand Down
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() {}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coroutine/issue-87142.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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;
}
Expand Down
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;
}
Expand Down
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 {}
Expand Down
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;
| ^^^^^^^^^^^
Expand Down
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]
Expand Down
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;
| ^^^^^^^^^^
Expand Down
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;

Expand Down
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
Expand Up @@ -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;
Expand Down
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 {
Expand Down
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
Expand All @@ -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 = ()>;
| ^^
Expand Down
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 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// edition: 2021
// build-pass: ICEd during codegen.

#![feature(impl_trait_in_assoc_type)]

use std::future::Future;

fn main() {
Expand Down
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 {}
Expand Down
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 {}
Expand Down
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 = ()>;
Expand Down
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
Expand All @@ -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;
| ^^^^^^^^^^
Expand Down
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
Expand Down
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
Expand All @@ -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 {}
| ^^^
Expand Down
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;

Expand Down
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
Expand All @@ -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`
Expand All @@ -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`
Expand Down
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;

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/issue-55872-2.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
--> $DIR/issue-55872-2.rs:14:9
--> $DIR/issue-55872-2.rs:12:9
|
LL | async {}
| ^^^^^^^^

error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
--> $DIR/issue-55872-2.rs:14:9
--> $DIR/issue-55872-2.rs:12:9
|
LL | async {}
| ^^^^^^^^
Expand Down
Loading

0 comments on commit a47c353

Please sign in to comment.