Rollup merge of #84168 - cjgillot:asi, r=davidtwco

Lower async fn in traits.

An error is already created by AST validation.

Fixes #84149
This commit is contained in:
Dylan DPC 2021-04-19 22:00:06 +02:00 committed by GitHub
commit e5b5745db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -836,9 +836,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
}
AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, Some(ref body))) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None, i.id);
let asyncness = sig.header.asyncness;
let body_id =
self.lower_maybe_async_body(i.span, &sig.decl, asyncness, Some(&body));
let (generics, sig) = self.lower_method_sig(
generics,
sig,
trait_item_def_id,
false,
asyncness.opt_return_id(),
i.id,
);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
}
AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref default)) => {

View File

@ -2,6 +2,10 @@
trait T {
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
async fn baz() { //~ ERROR functions in traits cannot be declared `async`
// Nested item must not ICE.
fn a() {}
}
}
fn main() {}

View File

@ -20,6 +20,22 @@ LL | async fn bar(&self) {}
= 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 2 previous errors
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/async-trait-fn.rs:5:5
|
LL | async fn baz() {
| ^----
| |
| _____`async` because of this
| |
LL | | // Nested item must not ICE.
LL | | fn a() {}
LL | | }
| |_____^
|
= 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 3 previous errors
For more information about this error, try `rustc --explain E0706`.