Skip to content

Commit 3c5bee0

Browse files
committed
Prereq3 for async drop - LangItem registration for async_drop_in_place<T>::{closure}
1 parent 286f4c0 commit 3c5bee0

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

compiler/rustc_hir/src/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ language_item_table! {
183183
AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::Exact(0);
184184
AsyncDestruct, sym::async_destruct, async_destruct_trait, Target::Trait, GenericRequirement::Exact(0);
185185
AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
186+
AsyncDropInPlacePoll, sym::async_drop_in_place_poll, async_drop_in_place_poll_fn, Target::Closure, GenericRequirement::Exact(1);
186187
SurfaceAsyncDropInPlace, sym::surface_async_drop_in_place, surface_async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
187188
AsyncDropSurfaceDropInPlace, sym::async_drop_surface_drop_in_place, async_drop_surface_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
188189
AsyncDropSlice, sym::async_drop_slice, async_drop_slice_fn, Target::Fn, GenericRequirement::Exact(1);

compiler/rustc_passes/src/lang_items.rs

+23
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
5858
&mut self,
5959
actual_target: Target,
6060
def_id: LocalDefId,
61+
cor_def_id: Option<LocalDefId>,
6162
attrs: &'ast [ast::Attribute],
6263
item_span: Span,
6364
generics: Option<&'ast ast::Generics>,
@@ -74,6 +75,18 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
7475
generics,
7576
actual_target,
7677
);
78+
// We need to register LangItem::AsyncDropInPlacePoll
79+
// for async_drop_in_place<T>::{closure}
80+
if cor_def_id.is_some() && lang_item == LangItem::AsyncDropInPlace {
81+
self.collect_item_extended(
82+
LangItem::AsyncDropInPlacePoll,
83+
cor_def_id.unwrap(),
84+
item_span,
85+
attr_span,
86+
generics,
87+
actual_target,
88+
);
89+
}
7790
}
7891
// Known lang item with attribute on incorrect target.
7992
Some(lang_item) => {
@@ -289,10 +302,18 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
289302
unreachable!("macros should have been expanded")
290303
}
291304
};
305+
let cor_def_id = if let ast::ItemKind::Fn(box ast::Fn { sig, .. }) = &i.kind
306+
&& let Some(kind) = sig.header.coroutine_kind
307+
{
308+
self.resolver.node_id_to_def_id.get(&kind.closure_id()).copied()
309+
} else {
310+
None
311+
};
292312

293313
self.check_for_lang(
294314
target,
295315
self.resolver.node_id_to_def_id[&i.id],
316+
cor_def_id,
296317
&i.attrs,
297318
i.span,
298319
i.opt_generics(),
@@ -308,6 +329,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
308329
self.check_for_lang(
309330
Target::Variant,
310331
self.resolver.node_id_to_def_id[&variant.id],
332+
None,
311333
&variant.attrs,
312334
variant.span,
313335
None,
@@ -350,6 +372,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
350372
self.check_for_lang(
351373
target,
352374
self.resolver.node_id_to_def_id[&i.id],
375+
None,
353376
&i.attrs,
354377
i.span,
355378
generics,

compiler/rustc_passes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![allow(internal_features)]
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1010
#![doc(rust_logo)]
11+
#![feature(box_patterns)]
1112
#![feature(let_chains)]
1213
#![feature(map_try_insert)]
1314
#![feature(rustdoc_internals)]

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ symbols! {
450450
async_drop_either,
451451
async_drop_fuse,
452452
async_drop_in_place,
453+
async_drop_in_place_poll,
453454
async_drop_noop,
454455
async_drop_slice,
455456
async_drop_surface_drop_in_place,

0 commit comments

Comments
 (0)