Skip to content

Commit f550ebe

Browse files
committed
Stabilize associated type position impl Trait (ATPIT)
1 parent f3b9d47 commit f550ebe

File tree

135 files changed

+130
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+130
-356
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,7 @@ impl<'a> PostExpansionVisitor<'a> {
120120
impl Visitor<'_> for ImplTraitVisitor<'_> {
121121
fn visit_ty(&mut self, ty: &ast::Ty) {
122122
if let ast::TyKind::ImplTrait(..) = ty.kind {
123-
if self.in_associated_ty {
124-
gate!(
125-
&self.vis,
126-
impl_trait_in_assoc_type,
127-
ty.span,
128-
"`impl Trait` in associated types is unstable"
129-
);
130-
} else {
123+
if !self.in_associated_ty {
131124
gate!(
132125
&self.vis,
133126
type_alias_impl_trait,

compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(iter_intersperse)]
1515
#![feature(let_chains)]
1616
#![feature(min_specialization)]
17-
#![feature(impl_trait_in_assoc_type)]
17+
#![cfg_attr(bootstrap, feature(impl_trait_in_assoc_type))]
1818
#![deny(rustc::untranslatable_diagnostic)]
1919
#![deny(rustc::diagnostic_outside_of_impl)]
2020

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ declare_features! (
197197
/// + `impl<I:Iterator> Iterator for &mut Iterator`
198198
/// + `impl Debug for Foo<'_>`
199199
(accepted, impl_header_lifetime_elision, "1.31.0", Some(15872)),
200+
/// Allows `impl Trait` to be used inside associated types (RFC 2515).
201+
(accepted, impl_trait_in_assoc_type, "CURRENT_RUSTC_VERSION", Some(63063)),
200202
/// Allows referencing `Self` and projections in impl-trait.
201203
(accepted, impl_trait_projections, "1.74.0", Some(103532)),
202204
/// Allows using `a..=b` and `..=b` as inclusive range syntaxes.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,6 @@ declare_features! (
485485
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
486486
/// Allows `if let` guard in match arms.
487487
(unstable, if_let_guard, "1.47.0", Some(51114)),
488-
/// Allows `impl Trait` to be used inside associated types (RFC 2515).
489-
(unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)),
490488
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.
491489
(unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)),
492490
/// Allows using imported `main` function

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(const_type_name)]
66
#![feature(cow_is_borrowed)]
77
#![feature(decl_macro)]
8-
#![feature(impl_trait_in_assoc_type)]
8+
#![cfg_attr(bootstrap, feature(impl_trait_in_assoc_type))]
99
#![feature(inline_const)]
1010
#![feature(is_sorted)]
1111
#![feature(let_chains)]

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![feature(assert_matches)]
77
#![feature(box_patterns)]
88
#![feature(if_let_guard)]
9-
#![feature(impl_trait_in_assoc_type)]
9+
#![cfg_attr(bootstrap, feature(impl_trait_in_assoc_type))]
1010
#![feature(iter_intersperse)]
1111
#![feature(lazy_cell)]
1212
#![feature(let_chains)]

tests/rustdoc/auxiliary/issue-73061.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//edition:2018
22

3-
#![feature(impl_trait_in_assoc_type)]
4-
53
pub trait Foo {
64
type X: std::future::Future<Output = ()>;
75
fn x(&self) -> Self::X;

tests/ui/associated-types/issue-63591.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// check-pass
22

33
#![feature(associated_type_bounds)]
4-
#![feature(impl_trait_in_assoc_type)]
54

65
fn main() {}
76

tests/ui/coroutine/issue-87142.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Regression test for #87142
55
// This test needs the above flags and the "lib" crate type.
66

7-
#![feature(impl_trait_in_assoc_type, coroutine_trait, coroutines)]
7+
#![feature(coroutine_trait, coroutines)]
88
#![crate_type = "lib"]
99

1010
use std::ops::Coroutine;

tests/ui/feature-gates/feature-gate-impl_trait_in_assoc_type.rs

-20
This file was deleted.

tests/ui/feature-gates/feature-gate-impl_trait_in_assoc_type.stderr

-49
This file was deleted.

tests/ui/generic-associated-types/issue-86218-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// check-pass
22

3-
#![feature(impl_trait_in_assoc_type)]
4-
53
pub trait Stream {
64
type Item;
75
}

tests/ui/generic-associated-types/issue-86218.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// check-pass
22

3-
#![feature(impl_trait_in_assoc_type)]
4-
53
pub trait Stream {
64
type Item;
75
}

tests/ui/generic-associated-types/issue-87258_a.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
2-
31
// See https://github.com/rust-lang/rust/issues/87258#issuecomment-883293367
42

53
trait Trait1 {}

tests/ui/generic-associated-types/issue-87258_a.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unconstrained opaque type
2-
--> $DIR/issue-87258_a.rs:17:26
2+
--> $DIR/issue-87258_a.rs:15:26
33
|
44
LL | type FooFuture<'a> = impl Trait1;
55
| ^^^^^^^^^^^

tests/ui/generic-associated-types/issue-88595.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
2-
31
fn main() {}
42

53
#[rustfmt::skip]

tests/ui/generic-associated-types/issue-88595.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: non-defining opaque type use in defining scope
2-
--> $DIR/issue-88595.rs:21:23
2+
--> $DIR/issue-88595.rs:19:23
33
|
44
LL | fn a(&'a self) -> Self::B<'a> {}
55
| ^^^^^^^^^^^ generic argument `'a` used twice
66
|
77
note: for this opaque type
8-
--> $DIR/issue-88595.rs:19:18
8+
--> $DIR/issue-88595.rs:17:18
99
|
1010
LL | type B<'b> = impl Clone;
1111
| ^^^^^^^^^^

tests/ui/generic-associated-types/issue-89008.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// check-pass
22
// edition:2021
33

4-
#![feature(impl_trait_in_assoc_type)]
5-
64
use std::future::Future;
75
use std::marker::PhantomData;
86

tests/ui/generic-associated-types/issue-90014-tait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// known-bug: unknown
55
// edition:2018
66

7-
#![feature(impl_trait_in_assoc_type, inherent_associated_types)]
7+
#![feature(inherent_associated_types)]
88
#![allow(incomplete_features)]
99

1010
use std::future::Future;

tests/ui/generic-associated-types/issue-90014.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// edition:2018
22

3-
#![feature(impl_trait_in_assoc_type)]
4-
53
use std::future::Future;
64

75
trait MakeFut {

tests/ui/generic-associated-types/issue-90014.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0477]: the type `&mut ()` does not fulfill the required lifetime
2-
--> $DIR/issue-90014.rs:15:20
2+
--> $DIR/issue-90014.rs:13:20
33
|
44
LL | type Fut<'a>
55
| ------------ definition of `Fut` from trait
@@ -8,7 +8,7 @@ LL | type Fut<'a> = impl Future<Output = ()>;
88
| ^^^^^^^^^^^^^^^^^^^^^^^^
99
|
1010
note: type must outlive the lifetime `'a` as defined here
11-
--> $DIR/issue-90014.rs:15:14
11+
--> $DIR/issue-90014.rs:13:14
1212
|
1313
LL | type Fut<'a> = impl Future<Output = ()>;
1414
| ^^

tests/ui/impl-trait/associated-impl-trait-type-generic-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
21
// build-pass (FIXME(62277): could be check-pass?)
32

43
trait Bar {}

tests/ui/impl-trait/associated-impl-trait-type-issue-114325.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// edition: 2021
55
// build-pass: ICEd during codegen.
66

7-
#![feature(impl_trait_in_assoc_type)]
8-
97
use std::future::Future;
108

119
fn main() {

tests/ui/impl-trait/associated-impl-trait-type-trivial.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
21
// build-pass (FIXME(62277): could be check-pass?)
32

43
trait Bar {}

tests/ui/impl-trait/associated-impl-trait-type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
21
// build-pass (FIXME(62277): could be check-pass?)
32

43
trait Bar {}

tests/ui/impl-trait/in-assoc-type-unconstrained.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
2-
31
mod compare_ty {
42
trait Trait {
53
type Ty: IntoIterator<Item = ()>;

tests/ui/impl-trait/in-assoc-type-unconstrained.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
error[E0271]: type mismatch resolving `<Option<<() as Trait>::Ty::{opaque#0}> as IntoIterator>::Item == ()`
2-
--> $DIR/in-assoc-type-unconstrained.rs:8:19
2+
--> $DIR/in-assoc-type-unconstrained.rs:6:19
33
|
44
LL | type Ty = Option<impl Sized>;
55
| ^^^^^^^^^^^^^^^^^^ expected `()`, found opaque type
66
|
77
= note: expected unit type `()`
88
found opaque type `<() as compare_ty::Trait>::Ty::{opaque#0}`
99
note: required by a bound in `compare_ty::Trait::Ty`
10-
--> $DIR/in-assoc-type-unconstrained.rs:5:31
10+
--> $DIR/in-assoc-type-unconstrained.rs:3:31
1111
|
1212
LL | type Ty: IntoIterator<Item = ()>;
1313
| ^^^^^^^^^ required by this bound in `Trait::Ty`
1414

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

2323
error[E0053]: method `method` has an incompatible type for trait
24-
--> $DIR/in-assoc-type-unconstrained.rs:22:24
24+
--> $DIR/in-assoc-type-unconstrained.rs:20:24
2525
|
2626
LL | type Ty = impl Sized;
2727
| ---------- the expected opaque type
@@ -33,20 +33,20 @@ LL | fn method() -> () {}
3333
| help: change the output type to match the trait: `<() as compare_method::Trait>::Ty`
3434
|
3535
note: type in trait
36-
--> $DIR/in-assoc-type-unconstrained.rs:17:24
36+
--> $DIR/in-assoc-type-unconstrained.rs:15:24
3737
|
3838
LL | fn method() -> Self::Ty;
3939
| ^^^^^^^^
4040
= note: expected signature `fn() -> <() as compare_method::Trait>::Ty`
4141
found signature `fn()`
4242
note: this item must have the opaque type in its signature in order to be able to register hidden types
43-
--> $DIR/in-assoc-type-unconstrained.rs:22:12
43+
--> $DIR/in-assoc-type-unconstrained.rs:20:12
4444
|
4545
LL | fn method() -> () {}
4646
| ^^^^^^
4747

4848
error: unconstrained opaque type
49-
--> $DIR/in-assoc-type-unconstrained.rs:20:19
49+
--> $DIR/in-assoc-type-unconstrained.rs:18:19
5050
|
5151
LL | type Ty = impl Sized;
5252
| ^^^^^^^^^^

tests/ui/impl-trait/in-assoc-type.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! This test checks that we don't allow registering hidden types for
22
//! opaque types from other impls.
33
4-
#![feature(impl_trait_in_assoc_type)]
5-
64
trait Foo<T> {
75
type Bar;
86
fn foo(&self) -> <Self as Foo<()>>::Bar

tests/ui/impl-trait/in-assoc-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/in-assoc-type.rs:20:22
2+
--> $DIR/in-assoc-type.rs:18:22
33
|
44
LL | type Bar = impl std::fmt::Debug;
55
| -------------------- the expected opaque type
@@ -12,7 +12,7 @@ LL | fn foo(&self) -> <Self as Foo<()>>::Bar {}
1212
= note: expected opaque type `<() as Foo<()>>::Bar`
1313
found unit type `()`
1414
note: this item must have the opaque type in its signature in order to be able to register hidden types
15-
--> $DIR/in-assoc-type.rs:20:8
15+
--> $DIR/in-assoc-type.rs:18:8
1616
|
1717
LL | fn foo(&self) -> <Self as Foo<()>>::Bar {}
1818
| ^^^

tests/ui/impl-trait/issue-55872-1.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(impl_trait_in_assoc_type)]
2-
31
pub trait Bar {
42
type E: Copy;
53

tests/ui/impl-trait/issue-55872-1.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0276]: impl has stricter requirements than trait
2-
--> $DIR/issue-55872-1.rs:12:15
2+
--> $DIR/issue-55872-1.rs:10:15
33
|
44
LL | fn foo<T>() -> Self::E;
55
| ----------------------- definition of `foo` from trait
@@ -8,7 +8,7 @@ LL | fn foo<T: Default>() -> Self::E {
88
| ^^^^^^^ impl has extra requirement `T: Default`
99

1010
error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
11-
--> $DIR/issue-55872-1.rs:12:29
11+
--> $DIR/issue-55872-1.rs:10:29
1212
|
1313
LL | fn foo<T: Default>() -> Self::E {
1414
| ^^^^^^^ 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 {
2020
| +++++++++++++++++++
2121

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

tests/ui/impl-trait/issue-55872-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// edition:2018
22

3-
#![feature(impl_trait_in_assoc_type)]
4-
53
pub trait Bar {
64
type E: Send;
75

0 commit comments

Comments
 (0)