Skip to content

Commit fa86106

Browse files
Stabilize AFIT and RPITIT
1 parent e5fedce commit fa86106

File tree

207 files changed

+258
-973
lines changed

Some content is hidden

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

207 files changed

+258
-973
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)
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
}
@@ -1923,18 +1896,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19231896
let future_bound = this.lower_async_fn_output_type_to_future_bound(
19241897
output,
19251898
span,
1926-
if let FnDeclKind::Trait = fn_kind
1927-
&& !this.tcx.features().return_position_impl_trait_in_trait
1928-
{
1929-
ImplTraitContext::FeatureGated(
1930-
ImplTraitPosition::TraitReturn,
1931-
sym::return_position_impl_trait_in_trait,
1932-
)
1933-
} else {
1934-
ImplTraitContext::ReturnPositionOpaqueTy {
1935-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1936-
fn_kind,
1937-
}
1899+
ImplTraitContext::ReturnPositionOpaqueTy {
1900+
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1901+
fn_kind,
19381902
},
19391903
);
19401904
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, "1.66.0", 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`.
@@ -302,6 +304,8 @@ declare_features! (
302304
(accepted, repr_packed, "1.33.0", Some(33158), None),
303305
/// Allows `#[repr(transparent)]` attribute on newtype structs.
304306
(accepted, repr_transparent, "1.28.0", Some(43036), None),
307+
/// Allows return-position `impl Trait` in traits.
308+
(accepted, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
305309
/// Allows code like `let x: &'static u32 = &42` to work (RFC 1414).
306310
(accepted, rvalue_static_promotion, "1.21.0", Some(38865), None),
307311
/// Allows `Self` in type definitions (RFC 2300).

compiler/rustc_feature/src/active.rs

-4
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ declare_features! (
338338
(active, associated_type_defaults, "1.2.0", Some(29661), None),
339339
/// Allows `async || body` closures.
340340
(active, async_closure, "1.37.0", Some(62290), None),
341-
/// Allows async functions to be declared, implemented, and used in traits.
342-
(active, async_fn_in_trait, "1.66.0", Some(91611), None),
343341
/// Allows `#[track_caller]` on async functions.
344342
(active, async_fn_track_caller, "1.73.0", Some(110011), None),
345343
/// Allows builtin # foo() syntax
@@ -540,8 +538,6 @@ declare_features! (
540538
(incomplete, repr128, "1.16.0", Some(56071), None),
541539
/// Allows `repr(simd)` and importing the various simd intrinsics.
542540
(active, repr_simd, "1.4.0", Some(27731), None),
543-
/// Allows return-position `impl Trait` in traits.
544-
(active, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
545541
/// Allows bounding the return type of AFIT/RPITIT.
546542
(incomplete, return_type_notation, "1.70.0", Some(109417), None),
547543
/// Allows `extern "rust-cold"`.

compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -904,21 +904,21 @@ fn check_impl_items_against_trait<'tcx>(
904904
let (msg, feature) = if tcx.asyncness(def_id).is_async() {
905905
(
906906
format!("async {descr} in trait cannot be specialized"),
907-
sym::async_fn_in_trait,
907+
"async functions in traits",
908908
)
909909
} else {
910910
(
911911
format!(
912912
"{descr} with return-position `impl Trait` in trait cannot be specialized"
913913
),
914-
sym::return_position_impl_trait_in_trait,
914+
"return position `impl Trait` in traits",
915915
)
916916
};
917917
tcx.sess
918918
.struct_span_err(tcx.def_span(def_id), msg)
919919
.note(format!(
920920
"specialization behaves in inconsistent and \
921-
surprising ways with `#![feature({feature})]`, \
921+
surprising ways with {feature}, \
922922
and for now is disallowed"
923923
))
924924
.emit();

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

-2
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,6 @@ fn compare_asyncness<'tcx>(
631631
/// For example, given the sample code:
632632
///
633633
/// ```
634-
/// #![feature(return_position_impl_trait_in_trait)]
635-
///
636634
/// use std::ops::Deref;
637635
///
638636
/// trait Foo {

compiler/rustc_lint_defs/src/builtin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4491,7 +4491,6 @@ declare_lint! {
44914491
/// ### Example
44924492
///
44934493
/// ```rust,compile_fail
4494-
/// #![feature(return_position_impl_trait_in_trait)]
44954494
/// #![deny(refining_impl_trait)]
44964495
///
44974496
/// 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/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;

tests/rustdoc/async-trait-sig.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// edition:2021
22

3-
#![feature(async_fn_in_trait)]
43
#![allow(incomplete_features)]
54

65
pub trait Foo {

tests/rustdoc/async-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// aux-build:async-trait-dep.rs
22
// edition:2021
33

4-
#![feature(async_fn_in_trait)]
54
#![allow(incomplete_features)]
65

76
extern crate async_trait_dep;

tests/rustdoc/auxiliary/async-trait-dep.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// edition:2021
22

3-
#![feature(async_fn_in_trait)]
43
#![allow(incomplete_features)]
54

65
pub trait Meow {

tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(return_position_impl_trait_in_trait)]
2-
31
pub trait Trait {
42
fn create() -> impl Iterator<Item = u64> {
53
std::iter::empty()

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
2525
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2626
--> $DIR/bad-inputs-and-output.rs:5:12
2727
|
28-
LL | #![feature(return_type_notation, async_fn_in_trait)]
28+
LL | #![feature(return_type_notation)]
2929
| ^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
2525
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2626
--> $DIR/bad-inputs-and-output.rs:5:12
2727
|
28-
LL | #![feature(return_type_notation, async_fn_in_trait)]
28+
LL | #![feature(return_type_notation)]
2929
| ^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// edition: 2021
22

3-
#![feature(return_type_notation, async_fn_in_trait)]
3+
#![feature(return_type_notation)]
44
//~^ WARN the feature `return_type_notation` is incomplete
55

66
trait Trait {

tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
2525
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2626
--> $DIR/bad-inputs-and-output.rs:3:12
2727
|
28-
LL | #![feature(return_type_notation, async_fn_in_trait)]
28+
LL | #![feature(return_type_notation)]
2929
| ^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/basic.current_with.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/basic.rs:8:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/basic.current_without.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/basic.rs:8:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/basic.next_with.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/basic.rs:8:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/basic.next_without.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/basic.rs:8:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/basic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// edition: 2021
33
// [with] check-pass
44

5-
#![feature(return_type_notation, async_fn_in_trait)]
5+
#![feature(return_type_notation)]
66
//~^ WARN the feature `return_type_notation` is incomplete
77

88
trait Foo {

tests/ui/associated-type-bounds/return-type-notation/basic.with.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/basic.rs:5:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/basic.without.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/basic.rs:5:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/equality.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/equality.rs:5:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/equality.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/equality.rs:5:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/equality.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// edition: 2021
22

3-
#![feature(return_type_notation, async_fn_in_trait)]
3+
#![feature(return_type_notation)]
44
//~^ WARN the feature `return_type_notation` is incomplete
55

66
use std::future::Future;

tests/ui/associated-type-bounds/return-type-notation/equality.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
22
--> $DIR/equality.rs:3:12
33
|
4-
LL | #![feature(return_type_notation, async_fn_in_trait)]
4+
LL | #![feature(return_type_notation)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information

tests/ui/associated-type-bounds/return-type-notation/missing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// edition: 2021
22

3-
#![feature(return_type_notation, async_fn_in_trait)]
3+
#![feature(return_type_notation)]
44
//~^ WARN the feature `return_type_notation` is incomplete
55

66
trait Trait {

0 commit comments

Comments
 (0)