Skip to content

Commit

Permalink
Stabilize AFIT and RPITIT
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 13, 2023
1 parent e5fedce commit fa86106
Show file tree
Hide file tree
Showing 207 changed files with 258 additions and 973 deletions.
70 changes: 17 additions & 53 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ enum ImplTraitPosition {
ClosureReturn,
PointerReturn,
FnTraitReturn,
TraitReturn,
ImplReturn,
GenericDefault,
ConstTy,
StaticTy,
Expand Down Expand Up @@ -302,8 +300,6 @@ impl std::fmt::Display for ImplTraitPosition {
ImplTraitPosition::ClosureReturn => "closure return types",
ImplTraitPosition::PointerReturn => "`fn` pointer return types",
ImplTraitPosition::FnTraitReturn => "`Fn` trait return types",
ImplTraitPosition::TraitReturn => "trait method return types",
ImplTraitPosition::ImplReturn => "`impl` method return types",
ImplTraitPosition::GenericDefault => "generic parameter defaults",
ImplTraitPosition::ConstTy => "const types",
ImplTraitPosition::StaticTy => "static types",
Expand Down Expand Up @@ -334,20 +330,16 @@ impl FnDeclKind {
matches!(self, FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait)
}

fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
fn return_impl_trait_allowed(&self) -> bool {
match self {
FnDeclKind::Fn | FnDeclKind::Inherent => true,
FnDeclKind::Impl if tcx.features().return_position_impl_trait_in_trait => true,
FnDeclKind::Trait if tcx.features().return_position_impl_trait_in_trait => true,
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
_ => false,
}
}

fn async_fn_allowed(&self, tcx: TyCtxt<'_>) -> bool {
fn async_fn_allowed(&self) -> bool {
match self {
FnDeclKind::Fn | FnDeclKind::Inherent => true,
FnDeclKind::Impl if tcx.features().async_fn_in_trait => true,
FnDeclKind::Trait if tcx.features().async_fn_in_trait => true,
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
_ => false,
}
}
Expand Down Expand Up @@ -1806,52 +1798,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}));

let output = if let Some((ret_id, span)) = make_ret_async {
if !kind.async_fn_allowed(self.tcx) {
match kind {
FnDeclKind::Trait | FnDeclKind::Impl => {
self.tcx
.sess
.create_feature_err(
TraitFnAsync { fn_span, span },
sym::async_fn_in_trait,
)
.emit();
}
_ => {
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
}
}
if !kind.async_fn_allowed() {
self.tcx.sess.emit_err(TraitFnAsync { fn_span, span });
}

let fn_def_id = self.local_def_id(fn_node_id);
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind)
} else {
match &decl.output {
FnRetTy::Ty(ty) => {
let context = if kind.return_impl_trait_allowed(self.tcx) {
let context = if kind.return_impl_trait_allowed() {
let fn_def_id = self.local_def_id(fn_node_id);
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
fn_kind: kind,
}
} else {
let position = match kind {
FnDeclKind::Fn | FnDeclKind::Inherent => {
unreachable!("fn should allow in-band lifetimes")
ImplTraitContext::Disallowed(match kind {
FnDeclKind::Fn
| FnDeclKind::Inherent
| FnDeclKind::Trait
| FnDeclKind::Impl => {
unreachable!("fn should allow return-position impl trait in traits")
}
FnDeclKind::ExternFn => ImplTraitPosition::ExternFnReturn,
FnDeclKind::Closure => ImplTraitPosition::ClosureReturn,
FnDeclKind::Pointer => ImplTraitPosition::PointerReturn,
FnDeclKind::Trait => ImplTraitPosition::TraitReturn,
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
};
match kind {
FnDeclKind::Trait | FnDeclKind::Impl => ImplTraitContext::FeatureGated(
position,
sym::return_position_impl_trait_in_trait,
),
_ => ImplTraitContext::Disallowed(position),
}
})
};
hir::FnRetTy::Return(self.lower_ty(ty, &context))
}
Expand Down Expand Up @@ -1923,18 +1896,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let future_bound = this.lower_async_fn_output_type_to_future_bound(
output,
span,
if let FnDeclKind::Trait = fn_kind
&& !this.tcx.features().return_position_impl_trait_in_trait
{
ImplTraitContext::FeatureGated(
ImplTraitPosition::TraitReturn,
sym::return_position_impl_trait_in_trait,
)
} else {
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
fn_kind,
}
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
fn_kind,
},
);
arena_vec![this; future_bound]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ declare_features! (
(accepted, associated_types, "1.0.0", None, None),
/// Allows free and inherent `async fn`s, `async` blocks, and `<expr>.await` expressions.
(accepted, async_await, "1.39.0", Some(50547), None),
/// Allows async functions to be declared, implemented, and used in traits.
(accepted, async_fn_in_trait, "1.66.0", Some(91611), None),
/// Allows all literals in attribute lists and values of key-value pairs.
(accepted, attr_literals, "1.30.0", Some(34981), None),
/// Allows overloading augmented assignment operations like `a += b`.
Expand Down Expand Up @@ -302,6 +304,8 @@ declare_features! (
(accepted, repr_packed, "1.33.0", Some(33158), None),
/// Allows `#[repr(transparent)]` attribute on newtype structs.
(accepted, repr_transparent, "1.28.0", Some(43036), None),
/// Allows return-position `impl Trait` in traits.
(accepted, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
/// Allows code like `let x: &'static u32 = &42` to work (RFC 1414).
(accepted, rvalue_static_promotion, "1.21.0", Some(38865), None),
/// Allows `Self` in type definitions (RFC 2300).
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ declare_features! (
(active, associated_type_defaults, "1.2.0", Some(29661), None),
/// Allows `async || body` closures.
(active, async_closure, "1.37.0", Some(62290), None),
/// Allows async functions to be declared, implemented, and used in traits.
(active, async_fn_in_trait, "1.66.0", Some(91611), None),
/// Allows `#[track_caller]` on async functions.
(active, async_fn_track_caller, "1.73.0", Some(110011), None),
/// Allows builtin # foo() syntax
Expand Down Expand Up @@ -540,8 +538,6 @@ declare_features! (
(incomplete, repr128, "1.16.0", Some(56071), None),
/// Allows `repr(simd)` and importing the various simd intrinsics.
(active, repr_simd, "1.4.0", Some(27731), None),
/// Allows return-position `impl Trait` in traits.
(active, return_position_impl_trait_in_trait, "1.65.0", Some(91611), None),
/// Allows bounding the return type of AFIT/RPITIT.
(incomplete, return_type_notation, "1.70.0", Some(109417), None),
/// Allows `extern "rust-cold"`.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,21 +904,21 @@ fn check_impl_items_against_trait<'tcx>(
let (msg, feature) = if tcx.asyncness(def_id).is_async() {
(
format!("async {descr} in trait cannot be specialized"),
sym::async_fn_in_trait,
"async functions in traits",
)
} else {
(
format!(
"{descr} with return-position `impl Trait` in trait cannot be specialized"
),
sym::return_position_impl_trait_in_trait,
"return position `impl Trait` in traits",
)
};
tcx.sess
.struct_span_err(tcx.def_span(def_id), msg)
.note(format!(
"specialization behaves in inconsistent and \
surprising ways with `#![feature({feature})]`, \
surprising ways with {feature}, \
and for now is disallowed"
))
.emit();
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,6 @@ fn compare_asyncness<'tcx>(
/// For example, given the sample code:
///
/// ```
/// #![feature(return_position_impl_trait_in_trait)]
///
/// use std::ops::Deref;
///
/// trait Foo {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4491,7 +4491,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// #![feature(return_position_impl_trait_in_trait)]
/// #![deny(refining_impl_trait)]
///
/// use std::fmt::Display;
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![warn(clippy::implied_bounds_in_impls)]
#![allow(dead_code)]
#![feature(return_position_impl_trait_in_trait)]

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

Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/implied_bounds_in_impls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![warn(clippy::implied_bounds_in_impls)]
#![allow(dead_code)]
#![feature(return_position_impl_trait_in_trait)]

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

Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/unused_async.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::unused_async)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use std::future::Future;
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc/async-trait-sig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// edition:2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

pub trait Foo {
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc/async-trait.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// aux-build:async-trait-dep.rs
// edition:2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

extern crate async_trait_dep;
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc/auxiliary/async-trait-dep.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// edition:2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

pub trait Meow {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(return_position_impl_trait_in_trait)]

pub trait Trait {
fn create() -> impl Iterator<Item = u64> {
std::iter::empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bad-inputs-and-output.rs:5:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bad-inputs-and-output.rs:5:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// edition: 2021

#![feature(return_type_notation, async_fn_in_trait)]
#![feature(return_type_notation)]
//~^ WARN the feature `return_type_notation` is incomplete

trait Trait {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LL | fn bar<T: Trait<method() -> (): Send>>() {}
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bad-inputs-and-output.rs:3:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/basic.rs:8:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/basic.rs:8:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/basic.rs:8:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/basic.rs:8:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// edition: 2021
// [with] check-pass

#![feature(return_type_notation, async_fn_in_trait)]
#![feature(return_type_notation)]
//~^ WARN the feature `return_type_notation` is incomplete

trait Foo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/basic.rs:5:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/basic.rs:5:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/equality.rs:5:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/equality.rs:5:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// edition: 2021

#![feature(return_type_notation, async_fn_in_trait)]
#![feature(return_type_notation)]
//~^ WARN the feature `return_type_notation` is incomplete

use std::future::Future;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/equality.rs:3:12
|
LL | #![feature(return_type_notation, async_fn_in_trait)]
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// edition: 2021

#![feature(return_type_notation, async_fn_in_trait)]
#![feature(return_type_notation)]
//~^ WARN the feature `return_type_notation` is incomplete

trait Trait {
Expand Down
Loading

0 comments on commit fa86106

Please sign in to comment.