Skip to content

Commit

Permalink
add incomplete feature async_fn_in_trait
Browse files Browse the repository at this point in the history
Doesn't do much yet, just disables the check preventing the use of the
syntax. Attempting to use it just results in ICE 🧊.
  • Loading branch information
ComputerDruid committed Aug 23, 2022
1 parent 015a824 commit 636cabc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ impl<'a> AstValidator<'a> {
}

fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) {
if let Async::Yes { span, .. } = asyncness {
self.session.emit_err(TraitFnAsync { fn_span, span });
if !self.session.features_untracked().async_fn_in_trait {
if let Async::Yes { span, .. } = asyncness {
self.session.emit_err(TraitFnAsync { fn_span, span });
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ 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),
/// Alows async functions to be declared, implemented, and used in traits.
(incomplete, async_fn_in_trait, "1.65.0", Some(91611), None),
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries.
(active, c_unwind, "1.52.0", Some(74990), None),
/// Allows using C-variadics.
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 @@ -389,6 +389,7 @@ symbols! {
assume_init,
async_await,
async_closure,
async_fn_in_trait,
atomic,
atomic_mod,
atomics,
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/async-await/feature-gate-async_fn_in_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// edition:2021

trait T {
async fn foo(); //~ ERROR functions in traits cannot be declared `async`
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/ui/async-await/feature-gate-async_fn_in_trait.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/feature-gate-async_fn_in_trait.rs:4:5
|
LL | async fn foo();
| -----^^^^^^^^^^
| |
| `async` because of this
|
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait

error: aborting due to previous error

For more information about this error, try `rustc --explain E0706`.

0 comments on commit 636cabc

Please sign in to comment.