Skip to content

Commit

Permalink
Gate async fn trait bound modifier on async_trait_bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 4, 2024
1 parent ae79233 commit 006acb0
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 42 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
"async closures are unstable",
"to use an async block, remove the `||`: `async {`"
);
gate_all!(
async_trait_bounds,
"`async` trait bounds are unstable",
"use the desugared name of the async trait, such as `AsyncFn`"
);
gate_all!(async_for_loop, "`for await` loops are experimental");
gate_all!(
closure_lifetime_binder,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ declare_features! (
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
/// Allows `for await` loops.
(unstable, async_for_loop, "1.77.0", Some(118898)),
/// Allows `async` trait bound modifier.
(unstable, async_trait_bounds, "CURRENT_RUSTC_VERSION", Some(62290)),
/// Allows using C-variadics.
(unstable, c_variadic, "1.34.0", Some(44930)),
/// Allows the use of `#[cfg(<true/false>)]`.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ impl<'a> Parser<'a> {
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018()
&& self.eat_keyword(kw::Async)
{
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
self.psess.gated_spans.gate(sym::async_trait_bounds, self.prev_token.span);
BoundAsyncness::Async(self.prev_token.span)
} else if self.may_recover()
&& self.token.uninterpolated_span().is_rust_2015()
Expand All @@ -954,7 +954,7 @@ impl<'a> Parser<'a> {
span: self.prev_token.span,
help: HelpUseLatestEdition::new(),
});
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
self.psess.gated_spans.gate(sym::async_trait_bounds, self.prev_token.span);
BoundAsyncness::Async(self.prev_token.span)
} else {
BoundAsyncness::Normal
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ symbols! {
async_for_loop,
async_iterator,
async_iterator_poll_next,
async_trait_bounds,
atomic,
atomic_mod,
atomics,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-fn/dyn-pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![feature(async_closure)]

fn foo(x: &dyn async Fn()) {}
fn foo(x: &dyn AsyncFn()) {}
//~^ ERROR the trait `AsyncFn` cannot be made into an object
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/async-await/async-fn/dyn-pos.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
LL | fn foo(x: &dyn AsyncFn()) {}
| ^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
Expand All @@ -16,8 +16,8 @@ note: for a trait to be "dyn-compatible" it needs to allow building a vtable to
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
LL | fn foo(x: &dyn AsyncFn()) {}
| ^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
Expand All @@ -32,8 +32,8 @@ note: for a trait to be "dyn-compatible" it needs to allow building a vtable to
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
LL | fn foo(x: &dyn AsyncFn()) {}
| ^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
Expand All @@ -48,8 +48,8 @@ note: for a trait to be "dyn-compatible" it needs to allow building a vtable to
error[E0038]: the trait `AsyncFn` cannot be made into an object
--> $DIR/dyn-pos.rs:5:12
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
LL | fn foo(x: &dyn AsyncFn()) {}
| ^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/async-fn/edition-2015.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn foo(x: impl async Fn()) -> impl async Fn() { x }
//~^ ERROR `async` trait bounds are only allowed in Rust 2018 or later
//~| ERROR `async` trait bounds are only allowed in Rust 2018 or later
//~| ERROR async closures are unstable
//~| ERROR async closures are unstable
//~| ERROR `async` trait bounds are unstable
//~| ERROR `async` trait bounds are unstable
//~| ERROR use of unstable library feature 'async_closure'
//~| ERROR use of unstable library feature 'async_closure'

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/async-await/async-fn/edition-2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
= help: pass `--edition 2021` to `rustc`
= note: for more on editions, read https://doc.rust-lang.org/edition-guide

error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/edition-2015.rs:1:16
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/edition-2015.rs:1:36
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() { x }
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error[E0658]: use of unstable library feature 'async_closure'
--> $DIR/edition-2015.rs:1:42
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ macro_rules! demo {
}

demo! { impl async Trait }
//~^ ERROR async closures are unstable
//~^ ERROR `async` trait bounds are unstable

demo! { dyn async Trait }
//~^ ERROR async closures are unstable
//~^ ERROR `async` trait bounds are unstable

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ LL | demo! { dyn async Trait }
|
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:15:14
|
LL | demo! { impl async Trait }
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:18:13
|
LL | demo! { dyn async Trait }
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error: aborting due to 4 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-fn/not-a-trait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition:2018

#![feature(async_closure)]
#![feature(async_trait_bounds)]

struct S;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-fn/sugar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ edition: 2021
//@ check-pass

#![feature(async_closure)]
#![feature(async_closure, async_trait_bounds)]

async fn foo() {}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-fn/trait-bounds-in-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macro_rules! x {

x! {
async fn foo() -> impl async Fn() { }
//~^ ERROR async closures are unstable
//~^ ERROR `async` trait bounds are unstable
}

fn main() {}
6 changes: 3 additions & 3 deletions tests/ui/async-await/async-fn/trait-bounds-in-macro.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/trait-bounds-in-macro.rs:8:28
|
LL | async fn foo() -> impl async Fn() { }
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-fn/wrong-trait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition:2018

#![feature(async_closure)]
#![feature(async_trait_bounds)]

trait Foo {}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/precise-capturing/bound-modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn polarity() -> impl Sized + ?use<> {}
fn asyncness() -> impl Sized + async use<> {}
//~^ ERROR expected identifier, found keyword `use`
//~| ERROR cannot find trait `r#use` in this scope
//~| ERROR async closures are unstable
//~| ERROR `async` trait bounds are unstable

fn constness() -> impl Sized + const use<> {}
//~^ ERROR expected identifier, found keyword `use`
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/impl-trait/precise-capturing/bound-modifiers.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ error[E0405]: cannot find trait `r#use` in this scope
LL | fn binder() -> impl Sized + for<'a> use<> {}
| ^^^ not found in this scope

error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/bound-modifiers.rs:9:32
|
LL | fn asyncness() -> impl Sized + async use<> {}
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error[E0658]: const trait impls are experimental
--> $DIR/bound-modifiers.rs:14:32
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/bad-recover-kw-after-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ macro_rules! impl_primitive {

impl_primitive!(impl async);
//~^ ERROR expected identifier, found `<eof>`
//~| ERROR async closures are unstable
//~| ERROR `async` trait bounds are unstable

fn main() {}
6 changes: 3 additions & 3 deletions tests/ui/parser/bad-recover-kw-after-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ LL | ($ty:ty) => {
LL | impl_primitive!(impl async);
| ^^^^^ expected identifier

error[E0658]: async closures are unstable
error[E0658]: `async` trait bounds are unstable
--> $DIR/bad-recover-kw-after-impl.rs:13:22
|
LL | impl_primitive!(impl async);
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
= help: add `#![feature(async_closure)]` to the crate attributes to enable
= help: add `#![feature(async_trait_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: to use an async block, remove the `||`: `async {`
= help: use the desugared name of the async trait, such as `AsyncFn`

error: aborting due to 2 previous errors

Expand Down

0 comments on commit 006acb0

Please sign in to comment.