Skip to content

Commit 3534899

Browse files
committed
Prereq3 for async drop - LangItem registration for async_drop_in_place<T>::{closure}
1 parent 746589b commit 3534899

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
@@ -191,6 +191,7 @@ language_item_table! {
191191
AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::Exact(0);
192192
AsyncDestruct, sym::async_destruct, async_destruct_trait, Target::Trait, GenericRequirement::Exact(0);
193193
AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
194+
AsyncDropInPlacePoll, sym::async_drop_in_place_poll, async_drop_in_place_poll_fn, Target::Closure, GenericRequirement::Exact(1);
194195
SurfaceAsyncDropInPlace, sym::surface_async_drop_in_place, surface_async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
195196
AsyncDropSurfaceDropInPlace, sym::async_drop_surface_drop_in_place, async_drop_surface_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
196197
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
@@ -57,6 +57,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
5757
&mut self,
5858
actual_target: Target,
5959
def_id: LocalDefId,
60+
cor_def_id: Option<LocalDefId>,
6061
attrs: &'ast [ast::Attribute],
6162
item_span: Span,
6263
generics: Option<&'ast ast::Generics>,
@@ -73,6 +74,18 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
7374
generics,
7475
actual_target,
7576
);
77+
// We need to register LangItem::AsyncDropInPlacePoll
78+
// for async_drop_in_place<T>::{closure}
79+
if cor_def_id.is_some() && lang_item == LangItem::AsyncDropInPlace {
80+
self.collect_item_extended(
81+
LangItem::AsyncDropInPlacePoll,
82+
cor_def_id.unwrap(),
83+
item_span,
84+
attr_span,
85+
generics,
86+
actual_target,
87+
);
88+
}
7689
}
7790
// Known lang item with attribute on incorrect target.
7891
Some(lang_item) => {
@@ -288,10 +301,18 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
288301
unreachable!("macros should have been expanded")
289302
}
290303
};
304+
let cor_def_id = if let ast::ItemKind::Fn(box ast::Fn { sig, .. }) = &i.kind
305+
&& let Some(kind) = sig.header.coroutine_kind
306+
{
307+
self.resolver.node_id_to_def_id.get(&kind.closure_id()).copied()
308+
} else {
309+
None
310+
};
291311

292312
self.check_for_lang(
293313
target,
294314
self.resolver.node_id_to_def_id[&i.id],
315+
cor_def_id,
295316
&i.attrs,
296317
i.span,
297318
i.opt_generics(),
@@ -307,6 +328,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
307328
self.check_for_lang(
308329
Target::Variant,
309330
self.resolver.node_id_to_def_id[&variant.id],
331+
None,
310332
&variant.attrs,
311333
variant.span,
312334
None,
@@ -349,6 +371,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
349371
self.check_for_lang(
350372
target,
351373
self.resolver.node_id_to_def_id[&i.id],
374+
None,
352375
&i.attrs,
353376
i.span,
354377
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
@@ -477,6 +477,7 @@ symbols! {
477477
async_drop_either,
478478
async_drop_fuse,
479479
async_drop_in_place,
480+
async_drop_in_place_poll,
480481
async_drop_noop,
481482
async_drop_slice,
482483
async_drop_surface_drop_in_place,

0 commit comments

Comments
 (0)