Skip to content

Commit 636cabc

Browse files
committed
add incomplete feature async_fn_in_trait
Doesn't do much yet, just disables the check preventing the use of the syntax. Attempting to use it just results in ICE 🧊.
1 parent 015a824 commit 636cabc

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ impl<'a> AstValidator<'a> {
286286
}
287287

288288
fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) {
289-
if let Async::Yes { span, .. } = asyncness {
290-
self.session.emit_err(TraitFnAsync { fn_span, span });
289+
if !self.session.features_untracked().async_fn_in_trait {
290+
if let Async::Yes { span, .. } = asyncness {
291+
self.session.emit_err(TraitFnAsync { fn_span, span });
292+
}
291293
}
292294
}
293295

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ declare_features! (
310310
(active, associated_type_defaults, "1.2.0", Some(29661), None),
311311
/// Allows `async || body` closures.
312312
(active, async_closure, "1.37.0", Some(62290), None),
313+
/// Alows async functions to be declared, implemented, and used in traits.
314+
(incomplete, async_fn_in_trait, "1.65.0", Some(91611), None),
313315
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries.
314316
(active, c_unwind, "1.52.0", Some(74990), None),
315317
/// Allows using C-variadics.

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ symbols! {
389389
assume_init,
390390
async_await,
391391
async_closure,
392+
async_fn_in_trait,
392393
atomic,
393394
atomic_mod,
394395
atomics,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// edition:2021
2+
3+
trait T {
4+
async fn foo(); //~ ERROR functions in traits cannot be declared `async`
5+
}
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0706]: functions in traits cannot be declared `async`
2+
--> $DIR/feature-gate-async_fn_in_trait.rs:4:5
3+
|
4+
LL | async fn foo();
5+
| -----^^^^^^^^^^
6+
| |
7+
| `async` because of this
8+
|
9+
= note: `async` trait functions are not currently supported
10+
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0706`.

0 commit comments

Comments
 (0)