Skip to content

Commit 59315b8

Browse files
Stabilize AFIT and RPITIT
1 parent 57ef889 commit 59315b8

File tree

229 files changed

+284
-1032
lines changed

Some content is hidden

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

229 files changed

+284
-1032
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+17-53
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ enum ImplTraitPosition {
271271
ClosureReturn,
272272
PointerReturn,
273273
FnTraitReturn,
274-
TraitReturn,
275-
ImplReturn,
276274
GenericDefault,
277275
ConstTy,
278276
StaticTy,
@@ -302,8 +300,6 @@ impl std::fmt::Display for ImplTraitPosition {
302300
ImplTraitPosition::ClosureReturn => "closure return types",
303301
ImplTraitPosition::PointerReturn => "`fn` pointer return types",
304302
ImplTraitPosition::FnTraitReturn => "`Fn` trait return types",
305-
ImplTraitPosition::TraitReturn => "trait method return types",
306-
ImplTraitPosition::ImplReturn => "`impl` method return types",
307303
ImplTraitPosition::GenericDefault => "generic parameter defaults",
308304
ImplTraitPosition::ConstTy => "const types",
309305
ImplTraitPosition::StaticTy => "static types",
@@ -334,20 +330,16 @@ impl FnDeclKind {
334330
matches!(self, FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait)
335331
}
336332

337-
fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
333+
fn return_impl_trait_allowed(&self) -> bool {
338334
match self {
339-
FnDeclKind::Fn | FnDeclKind::Inherent => true,
340-
FnDeclKind::Impl if tcx.features().return_position_impl_trait_in_trait => true,
341-
FnDeclKind::Trait if tcx.features().return_position_impl_trait_in_trait => true,
335+
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
342336
_ => false,
343337
}
344338
}
345339

346-
fn async_fn_allowed(&self, tcx: TyCtxt<'_>) -> bool {
340+
fn async_fn_allowed(&self) -> bool {
347341
match self {
348-
FnDeclKind::Fn | FnDeclKind::Inherent => true,
349-
FnDeclKind::Impl if tcx.features().async_fn_in_trait => true,
350-
FnDeclKind::Trait if tcx.features().async_fn_in_trait => true,
342+
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
351343
_ => false,
352344
}
353345
}
@@ -1806,52 +1798,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18061798
}));
18071799

18081800
let output = if let Some((ret_id, span)) = make_ret_async {
1809-
if !kind.async_fn_allowed(self.tcx) {
1810-
match kind {
1811-
FnDeclKind::Trait | FnDeclKind::Impl => {
1812-
self.tcx
1813-
.sess
1814-
.create_feature_err(
1815-
TraitFnAsync { fn_span, span },
1816-
sym::async_fn_in_trait,
1817-
)
1818-
.emit();
1819-
}
1820-
_ => {
1821-
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
1822-
}
1823-
}
1801+
if !kind.async_fn_allowed() {
1802+
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
18241803
}
18251804

18261805
let fn_def_id = self.local_def_id(fn_node_id);
18271806
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind, fn_span)
18281807
} else {
18291808
match &decl.output {
18301809
FnRetTy::Ty(ty) => {
1831-
let context = if kind.return_impl_trait_allowed(self.tcx) {
1810+
let context = if kind.return_impl_trait_allowed() {
18321811
let fn_def_id = self.local_def_id(fn_node_id);
18331812
ImplTraitContext::ReturnPositionOpaqueTy {
18341813
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
18351814
fn_kind: kind,
18361815
}
18371816
} else {
1838-
let position = match kind {
1839-
FnDeclKind::Fn | FnDeclKind::Inherent => {
1840-
unreachable!("fn should allow in-band lifetimes")
1817+
ImplTraitContext::Disallowed(match kind {
1818+
FnDeclKind::Fn
1819+
| FnDeclKind::Inherent
1820+
| FnDeclKind::Trait
1821+
| FnDeclKind::Impl => {
1822+
unreachable!("fn should allow return-position impl trait in traits")
18411823
}
18421824
FnDeclKind::ExternFn => ImplTraitPosition::ExternFnReturn,
18431825
FnDeclKind::Closure => ImplTraitPosition::ClosureReturn,
18441826
FnDeclKind::Pointer => ImplTraitPosition::PointerReturn,
1845-
FnDeclKind::Trait => ImplTraitPosition::TraitReturn,
1846-
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
1847-
};
1848-
match kind {
1849-
FnDeclKind::Trait | FnDeclKind::Impl => ImplTraitContext::FeatureGated(
1850-
position,
1851-
sym::return_position_impl_trait_in_trait,
1852-
),
1853-
_ => ImplTraitContext::Disallowed(position),
1854-
}
1827+
})
18551828
};
18561829
hir::FnRetTy::Return(self.lower_ty(ty, &context))
18571830
}
@@ -1924,18 +1897,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19241897
let future_bound = this.lower_async_fn_output_type_to_future_bound(
19251898
output,
19261899
span,
1927-
if let FnDeclKind::Trait = fn_kind
1928-
&& !this.tcx.features().return_position_impl_trait_in_trait
1929-
{
1930-
ImplTraitContext::FeatureGated(
1931-
ImplTraitPosition::TraitReturn,
1932-
sym::return_position_impl_trait_in_trait,
1933-
)
1934-
} else {
1935-
ImplTraitContext::ReturnPositionOpaqueTy {
1936-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1937-
fn_kind,
1938-
}
1900+
ImplTraitContext::ReturnPositionOpaqueTy {
1901+
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1902+
fn_kind,
19391903
},
19401904
);
19411905
arena_vec![this; future_bound]

compiler/rustc_feature/src/accepted.rs

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ declare_features! (
6767
(accepted, associated_types, "1.0.0", None, None),
6868
/// Allows free and inherent `async fn`s, `async` blocks, and `<expr>.await` expressions.
6969
(accepted, async_await, "1.39.0", Some(50547), None),
70+
/// Allows async functions to be declared, implemented, and used in traits.
71+
(accepted, async_fn_in_trait, "CURRENT_RUSTC_VERSION", Some(91611), None),
7072
/// Allows all literals in attribute lists and values of key-value pairs.
7173
(accepted, attr_literals, "1.30.0", Some(34981), None),
7274
/// Allows overloading augmented assignment operations like `a += b`.
@@ -306,6 +308,8 @@ declare_features! (
306308
(accepted, repr_packed, "1.33.0", Some(33158), None),
307309
/// Allows `#[repr(transparent)]` attribute on newtype structs.
308310
(accepted, repr_transparent, "1.28.0", Some(43036), None),
311+
/// Allows return-position `impl Trait` in traits.
312+
(accepted, return_position_impl_trait_in_trait, "CURRENT_RUSTC_VERSION", Some(91611), None),
309313
/// Allows code like `let x: &'static u32 = &42` to work (RFC 1414).
310314
(accepted, rvalue_static_promotion, "1.21.0", Some(38865), None),
311315
/// Allows `Self` in type definitions (RFC 2300).

compiler/rustc_feature/src/active.rs

-4
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ declare_features! (
351351
(active, associated_type_defaults, "1.2.0", Some(29661), None),
352352
/// Allows `async || body` closures.
353353
(active, async_closure, "1.37.0", Some(62290), None),
354-
/// Allows async functions to be declared, implemented, and used in traits.
355-
(active, async_fn_in_trait, "1.66.0", Some(91611), None),
356354
/// Allows `#[track_caller]` on async functions.
357355
(active, async_fn_track_caller, "1.73.0", Some(110011), None),
358356
/// Allows builtin # foo() syntax
@@ -551,8 +549,6 @@ declare_features! (
551549
(incomplete, repr128, "1.16.0", Some(56071), None),
552550
/// Allows `repr(simd)` and importing the various simd intrinsics.
553551
(active, repr_simd, "1.4.0", Some(27731), None),
554-
/// Allows return-position `impl Trait` in traits.
555-
(active, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
556552
/// Allows bounding the return type of AFIT/RPITIT.
557553
(incomplete, return_type_notation, "1.70.0", Some(109417), None),
558554
/// Allows `extern "rust-cold"`.

compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -783,21 +783,21 @@ fn check_impl_items_against_trait<'tcx>(
783783
let (msg, feature) = if tcx.asyncness(def_id).is_async() {
784784
(
785785
format!("async {descr} in trait cannot be specialized"),
786-
sym::async_fn_in_trait,
786+
"async functions in traits",
787787
)
788788
} else {
789789
(
790790
format!(
791791
"{descr} with return-position `impl Trait` in trait cannot be specialized"
792792
),
793-
sym::return_position_impl_trait_in_trait,
793+
"return position `impl Trait` in traits",
794794
)
795795
};
796796
tcx.sess
797797
.struct_span_err(tcx.def_span(def_id), msg)
798798
.note(format!(
799799
"specialization behaves in inconsistent and \
800-
surprising ways with `#![feature({feature})]`, \
800+
surprising ways with {feature}, \
801801
and for now is disallowed"
802802
))
803803
.emit();

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

-2
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,6 @@ fn compare_asyncness<'tcx>(
633633
/// For example, given the sample code:
634634
///
635635
/// ```
636-
/// #![feature(return_position_impl_trait_in_trait)]
637-
///
638636
/// use std::ops::Deref;
639637
///
640638
/// trait Foo {

compiler/rustc_lint/src/async_fn_in_trait.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ declare_lint! {
1111
/// ### Example
1212
///
1313
/// ```rust
14-
/// # #![feature(async_fn_in_trait)]
1514
/// pub trait Trait {
1615
/// async fn method(&self);
1716
/// }
@@ -33,7 +32,6 @@ declare_lint! {
3332
/// For example, this code is invalid:
3433
///
3534
/// ```rust,compile_fail
36-
/// # #![feature(async_fn_in_trait)]
3735
/// pub trait Trait {
3836
/// async fn method(&self) {}
3937
/// }
@@ -51,7 +49,6 @@ declare_lint! {
5149
/// For example, instead of:
5250
///
5351
/// ```rust
54-
/// # #![feature(async_fn_in_trait)]
5552
/// pub trait Trait {
5653
/// async fn method(&self) {}
5754
/// }

compiler/rustc_lint_defs/src/builtin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4574,7 +4574,6 @@ declare_lint! {
45744574
/// ### Example
45754575
///
45764576
/// ```rust,compile_fail
4577-
/// #![feature(return_position_impl_trait_in_trait)]
45784577
/// #![deny(refining_impl_trait)]
45794578
///
45804579
/// use std::fmt::Display;

src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![warn(clippy::implied_bounds_in_impls)]
22
#![allow(dead_code)]
3-
#![feature(return_position_impl_trait_in_trait)]
43

54
use std::ops::{Deref, DerefMut};
65

src/tools/clippy/tests/ui/implied_bounds_in_impls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![warn(clippy::implied_bounds_in_impls)]
22
#![allow(dead_code)]
3-
#![feature(return_position_impl_trait_in_trait)]
43

54
use std::ops::{Deref, DerefMut};
65

src/tools/clippy/tests/ui/implied_bounds_in_impls.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this bound is already specified as the supertrait of `DerefMut<Target = T>`
2-
--> $DIR/implied_bounds_in_impls.rs:13:36
2+
--> $DIR/implied_bounds_in_impls.rs:12:36
33
|
44
LL | fn deref_derefmut<T>(x: T) -> impl Deref<Target = T> + DerefMut<Target = T> {
55
| ^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL + fn deref_derefmut<T>(x: T) -> impl DerefMut<Target = T> {
1313
|
1414

1515
error: this bound is already specified as the supertrait of `GenericSubtrait<U, W, U>`
16-
--> $DIR/implied_bounds_in_impls.rs:30:37
16+
--> $DIR/implied_bounds_in_impls.rs:29:37
1717
|
1818
LL | fn generics_implied<U, W>() -> impl GenericTrait<W> + GenericSubtrait<U, W, U>
1919
| ^^^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL + fn generics_implied<U, W>() -> impl GenericSubtrait<U, W, U>
2525
|
2626

2727
error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>`
28-
--> $DIR/implied_bounds_in_impls.rs:36:40
28+
--> $DIR/implied_bounds_in_impls.rs:35:40
2929
|
3030
LL | fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
3131
| ^^^^^^^^^^^^^^^^^
@@ -37,7 +37,7 @@ LL + fn generics_implied_multi<V>() -> impl GenericTrait2<V> + GenericSubtrait<(
3737
|
3838

3939
error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>`
40-
--> $DIR/implied_bounds_in_impls.rs:36:60
40+
--> $DIR/implied_bounds_in_impls.rs:35:60
4141
|
4242
LL | fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
4343
| ^^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL + fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericSubtrait<
4949
|
5050

5151
error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>`
52-
--> $DIR/implied_bounds_in_impls.rs:38:44
52+
--> $DIR/implied_bounds_in_impls.rs:37:44
5353
|
5454
LL | fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericTrait2<V> + GenericSubtrait<(), T, V>
5555
| ^^^^^^^^^^^^^^^
@@ -61,7 +61,7 @@ LL + fn generics_implied_multi2<T, V>() -> impl GenericTrait2<V> + GenericSubtra
6161
|
6262

6363
error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>`
64-
--> $DIR/implied_bounds_in_impls.rs:38:62
64+
--> $DIR/implied_bounds_in_impls.rs:37:62
6565
|
6666
LL | fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericTrait2<V> + GenericSubtrait<(), T, V>
6767
| ^^^^^^^^^^^^^^^^
@@ -73,7 +73,7 @@ LL + fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericSubtrai
7373
|
7474

7575
error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>`
76-
--> $DIR/implied_bounds_in_impls.rs:48:28
76+
--> $DIR/implied_bounds_in_impls.rs:47:28
7777
|
7878
LL | fn generics_same() -> impl GenericTrait<i32> + GenericSubtrait<(), i32, ()> {}
7979
| ^^^^^^^^^^^^^^^^^
@@ -85,7 +85,7 @@ LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {}
8585
|
8686

8787
error: this bound is already specified as the supertrait of `DerefMut<Target = u8>`
88-
--> $DIR/implied_bounds_in_impls.rs:52:20
88+
--> $DIR/implied_bounds_in_impls.rs:51:20
8989
|
9090
LL | fn f() -> impl Deref + DerefMut<Target = u8>;
9191
| ^^^^^
@@ -97,7 +97,7 @@ LL + fn f() -> impl DerefMut<Target = u8>;
9797
|
9898

9999
error: this bound is already specified as the supertrait of `DerefMut<Target = u8>`
100-
--> $DIR/implied_bounds_in_impls.rs:57:20
100+
--> $DIR/implied_bounds_in_impls.rs:56:20
101101
|
102102
LL | fn f() -> impl Deref + DerefMut<Target = u8> {
103103
| ^^^^^
@@ -109,7 +109,7 @@ LL + fn f() -> impl DerefMut<Target = u8> {
109109
|
110110

111111
error: this bound is already specified as the supertrait of `DerefMut<Target = u8>`
112-
--> $DIR/implied_bounds_in_impls.rs:63:20
112+
--> $DIR/implied_bounds_in_impls.rs:62:20
113113
|
114114
LL | fn f() -> impl Deref + DerefMut<Target = u8> {
115115
| ^^^^^
@@ -121,7 +121,7 @@ LL + fn f() -> impl DerefMut<Target = u8> {
121121
|
122122

123123
error: this bound is already specified as the supertrait of `PartialOrd`
124-
--> $DIR/implied_bounds_in_impls.rs:74:41
124+
--> $DIR/implied_bounds_in_impls.rs:73:41
125125
|
126126
LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
127127
| ^^^^^^^^^
@@ -133,7 +133,7 @@ LL + fn default_generic_param1() -> impl PartialOrd + Debug {}
133133
|
134134

135135
error: this bound is already specified as the supertrait of `PartialOrd`
136-
--> $DIR/implied_bounds_in_impls.rs:75:54
136+
--> $DIR/implied_bounds_in_impls.rs:74:54
137137
|
138138
LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
139139
| ^^^^^^^^^
@@ -145,7 +145,7 @@ LL + fn default_generic_param2() -> impl PartialOrd + Debug {}
145145
|
146146

147147
error: this bound is already specified as the supertrait of `DoubleEndedIterator`
148-
--> $DIR/implied_bounds_in_impls.rs:88:26
148+
--> $DIR/implied_bounds_in_impls.rs:87:26
149149
|
150150
LL | fn my_iter() -> impl Iterator<Item = u32> + DoubleEndedIterator {
151151
| ^^^^^^^^^^^^^^^^^^^^
@@ -157,7 +157,7 @@ LL + fn my_iter() -> impl DoubleEndedIterator<Item = u32> {
157157
|
158158

159159
error: this bound is already specified as the supertrait of `Copy`
160-
--> $DIR/implied_bounds_in_impls.rs:93:27
160+
--> $DIR/implied_bounds_in_impls.rs:92:27
161161
|
162162
LL | fn f() -> impl Copy + Clone {
163163
| ^^^^^
@@ -169,7 +169,7 @@ LL + fn f() -> impl Copy {
169169
|
170170

171171
error: this bound is already specified as the supertrait of `Trait2<i32>`
172-
--> $DIR/implied_bounds_in_impls.rs:107:21
172+
--> $DIR/implied_bounds_in_impls.rs:106:21
173173
|
174174
LL | fn f2() -> impl Trait1<i32, U = i64> + Trait2<i32> {}
175175
| ^^^^^^^^^^^^^^^^^^^^
@@ -181,7 +181,7 @@ LL + fn f2() -> impl Trait2<i32, U = i64> {}
181181
|
182182

183183
error: this bound is already specified as the supertrait of `Trait4<i8, X = i32>`
184-
--> $DIR/implied_bounds_in_impls.rs:122:21
184+
--> $DIR/implied_bounds_in_impls.rs:121:21
185185
|
186186
LL | fn f3() -> impl Trait3<i8, i16, i64, X = i32, Y = i128> + Trait4<i8, X = i32> {}
187187
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/tools/clippy/tests/ui/unused_async.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![warn(clippy::unused_async)]
2-
#![feature(async_fn_in_trait)]
32
#![allow(incomplete_features)]
43

54
use std::future::Future;

0 commit comments

Comments
 (0)