Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ fn needs_drop_raw<'tcx>(
// needs drop.
let adt_has_dtor =
|adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant);
let res = drop_tys_helper(tcx, query.value, query.typing_env, adt_has_dtor, false, false)
.filter(filter_array_elements(tcx, query.typing_env))
.next()
.is_some();
let res =
drop_tys_helper(tcx, query.value, query.typing_env, adt_has_dtor, false, false, false)
.filter(filter_array_elements(tcx, query.typing_env))
.next()
.is_some();

debug!("needs_drop_raw({:?}) = {:?}", query, res);
res
Expand All @@ -41,10 +42,11 @@ fn needs_async_drop_raw<'tcx>(
// it needs async drop.
let adt_has_async_dtor =
|adt_def: ty::AdtDef<'tcx>| adt_def.async_destructor(tcx).map(|_| DtorType::Significant);
let res = drop_tys_helper(tcx, query.value, query.typing_env, adt_has_async_dtor, false, false)
.filter(filter_array_elements_async(tcx, query.typing_env))
.next()
.is_some();
let res =
drop_tys_helper(tcx, query.value, query.typing_env, adt_has_async_dtor, false, false, true)
.filter(filter_array_elements_async(tcx, query.typing_env))
.next()
.is_some();

debug!("needs_async_drop_raw({:?}) = {:?}", query, res);
res
Expand Down Expand Up @@ -90,6 +92,7 @@ fn has_significant_drop_raw<'tcx>(
adt_consider_insignificant_dtor(tcx),
true,
false,
false,
)
.filter(filter_array_elements(tcx, query.typing_env))
.next()
Expand Down Expand Up @@ -331,6 +334,7 @@ fn drop_tys_helper<'tcx>(
adt_has_dtor: impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType>,
only_significant: bool,
exhaustive: bool,
async_drop_recurses_into_box: bool,
) -> impl Iterator<Item = NeedsDropResult<Ty<'tcx>>> {
fn with_query_cache<'tcx>(
tcx: TyCtxt<'tcx>,
Expand All @@ -353,6 +357,14 @@ fn drop_tys_helper<'tcx>(
if adt_def.is_manually_drop() {
debug!("drop_tys_helper: `{:?}` is manually drop", adt_def);
Ok(Vec::new())
} else if async_drop_recurses_into_box && adt_def.is_box() {
let boxed_ty = args.type_at(0);
let allocator_ty = args.get(1).map(|arg| arg.expect_ty());
let boxed_ty = match boxed_ty.kind() {
ty::Dynamic(..) | ty::Error(_) => None,
_ => Some(boxed_ty),
};
Ok([boxed_ty, allocator_ty].into_iter().flatten().collect())
} else if let Some(dtor_info) = adt_has_dtor(adt_def) {
match dtor_info {
DtorType::Significant => {
Expand Down Expand Up @@ -435,6 +447,7 @@ fn adt_drop_tys<'tcx>(
adt_has_dtor,
false,
false,
false,
)
.collect::<Result<Vec<_>, _>>()
.map(|components| tcx.mk_type_list(&components))
Expand All @@ -455,6 +468,7 @@ fn adt_async_drop_tys<'tcx>(
adt_has_dtor,
false,
false,
true,
)
.collect::<Result<Vec<_>, _>>()
.map(|components| tcx.mk_type_list(&components))
Expand All @@ -474,6 +488,7 @@ fn adt_significant_drop_tys(
adt_consider_insignificant_dtor(tcx),
true,
false,
false,
)
.collect::<Result<Vec<_>, _>>()
.map(|components| tcx.mk_type_list(&components))
Expand All @@ -492,6 +507,7 @@ fn list_significant_drop_tys<'tcx>(
adt_consider_insignificant_dtor(tcx),
true,
true,
false,
)
.filter_map(|res| res.ok())
.collect::<Vec<_>>(),
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/async-await/async-drop/async-drop-box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
// `Foo` is always inside `Box`
// Sync version is called in sync context, async version is called in async function.

//@ known-bug: #143658
// async version is never actually called

#![feature(async_drop)]
#![allow(incomplete_features)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-box.run.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Foo::new() : 7
Foo::drop() : 7
Middle
Foo::new() : 10
Foo::drop() : 10
Foo::async drop() : 10
Done
Loading