Rollup merge of #142606 - azhogin:azhogin/async-drop-without-sync-drop-error, r=oli-obk

AsyncDrop trait without sync Drop generates an error

When type implements `AsyncDrop` trait, it must also implement sync `Drop` trait to be used in sync context and unwinds.
This PR adds error generation in such a case.

Fixes: rust-lang/rust#140696
This commit is contained in:
Trevor Gross
2025-06-18 20:22:50 -04:00
committed by GitHub
5 changed files with 49 additions and 1 deletions

View File

@@ -114,7 +114,15 @@ pub fn provide(providers: &mut Providers) {
}
fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Destructor> {
tcx.calculate_dtor(def_id, always_applicable::check_drop_impl)
let dtor = tcx.calculate_dtor(def_id, always_applicable::check_drop_impl);
if dtor.is_none() && tcx.features().async_drop() {
if let Some(async_dtor) = adt_async_destructor(tcx, def_id) {
// When type has AsyncDrop impl, but doesn't have Drop impl, generate error
let span = tcx.def_span(async_dtor.impl_did);
tcx.dcx().emit_err(errors::AsyncDropWithoutSyncDrop { span });
}
}
dtor
}
fn adt_async_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::AsyncDestructor> {