Avoid creating async return opaques for foreign async fns

This commit is contained in:
mu001999
2026-04-01 10:48:35 +08:00
parent 4cf5f95802
commit 8277043ea3
3 changed files with 34 additions and 2 deletions
+5 -2
View File
@@ -209,12 +209,15 @@ fn visit_item(&mut self, i: &'a Item) {
fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
match fn_kind {
FnKind::Fn(
_ctxt,
ctxt,
_vis,
Fn {
sig: FnSig { header, decl, span: _ }, ident, generics, contract, body, ..
},
) if let Some(coroutine_kind) = header.coroutine_kind => {
) if let Some(coroutine_kind) = header.coroutine_kind
// Foreign ones are denied, so don't create them here.
&& ctxt != visit::FnCtxt::Foreign =>
{
self.visit_ident(ident);
self.visit_fn_header(header);
self.visit_generics(generics);
+8
View File
@@ -0,0 +1,8 @@
//@ edition:2024
#![crate_type = "lib"]
unsafe extern "C" {
async fn function() -> [(); || {}];
//~^ ERROR functions in `extern` blocks cannot have `async` qualifier
//~^^ ERROR mismatched types
}
@@ -0,0 +1,21 @@
error: functions in `extern` blocks cannot have `async` qualifier
--> $DIR/bad-external-async-fn-issue-146754.rs:5:5
|
LL | unsafe extern "C" {
| ----------------- in this `extern` block
LL | async fn function() -> [(); || {}];
| ^^^^^ help: remove the `async` qualifier
error[E0308]: mismatched types
--> $DIR/bad-external-async-fn-issue-146754.rs:5:33
|
LL | async fn function() -> [(); || {}];
| ^^^^^ expected `usize`, found closure
|
= note: expected type `usize`
found closure `{closure@$DIR/bad-external-async-fn-issue-146754.rs:5:33: 5:35}`
= note: array length can only be `usize`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.