Skip to content

Commit b2bd30d

Browse files
authored
Unrolled build for #154660
Rollup merge of #154660 - mu001999-contrib:fix/146754, r=Kivooeo Avoid creating async return opaques for foreign async fns Fixes #146754 Previously, def collection created the desugared async return opaque for foreign `async fn` items, but AST lowering won't lower that opaque for foreign items. That left a `DefId` without a corresponding HIR owner, which later caused an ICE during analysis.
2 parents e6b64a2 + 8277043 commit b2bd30d

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

‎compiler/rustc_resolve/src/def_collector.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
209209
fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
210210
match fn_kind {
211211
FnKind::Fn(
212-
_ctxt,
212+
ctxt,
213213
_vis,
214214
Fn {
215215
sig: FnSig { header, decl, span: _ }, ident, generics, contract, body, ..
216216
},
217-
) if let Some(coroutine_kind) = header.coroutine_kind => {
217+
) if let Some(coroutine_kind) = header.coroutine_kind
218+
// Foreign ones are denied, so don't create them here.
219+
&& ctxt != visit::FnCtxt::Foreign =>
220+
{
218221
self.visit_ident(ident);
219222
self.visit_fn_header(header);
220223
self.visit_generics(generics);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ edition:2024
2+
#![crate_type = "lib"]
3+
4+
unsafe extern "C" {
5+
async fn function() -> [(); || {}];
6+
//~^ ERROR functions in `extern` blocks cannot have `async` qualifier
7+
//~^^ ERROR mismatched types
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: functions in `extern` blocks cannot have `async` qualifier
2+
--> $DIR/bad-external-async-fn-issue-146754.rs:5:5
3+
|
4+
LL | unsafe extern "C" {
5+
| ----------------- in this `extern` block
6+
LL | async fn function() -> [(); || {}];
7+
| ^^^^^ help: remove the `async` qualifier
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/bad-external-async-fn-issue-146754.rs:5:33
11+
|
12+
LL | async fn function() -> [(); || {}];
13+
| ^^^^^ expected `usize`, found closure
14+
|
15+
= note: expected type `usize`
16+
found closure `{closure@$DIR/bad-external-async-fn-issue-146754.rs:5:33: 5:35}`
17+
= note: array length can only be `usize`
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)