From a2618e1af04401513252097235e99f8b81588b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maja=20K=C4=85dzio=C5=82ka?= Date: Fri, 4 Apr 2025 04:56:18 +0200 Subject: [PATCH] AsyncDestructor: replace fields with impl_did MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The future and ctor fields aren't actually used, and the way they are extracted is obviously wrong – swapping the order of the items in the source code will give wrong results. Instead, store just the LocalDefId of the impl, which is enough for the only use of this data. --- compiler/rustc_middle/src/ty/mod.rs | 6 ++---- .../rustc_middle/src/ty/significant_drop_order.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 15 +++------------ 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 255d464d26541..23955f911184b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1124,10 +1124,8 @@ pub struct Destructor { // FIXME: consider combining this definition with regular `Destructor` #[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)] pub struct AsyncDestructor { - /// The `DefId` of the async destructor future constructor - pub ctor: DefId, - /// The `DefId` of the async destructor future type - pub future: DefId, + /// The `DefId` of the `impl AsyncDrop` + pub impl_did: LocalDefId, } #[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] diff --git a/compiler/rustc_middle/src/ty/significant_drop_order.rs b/compiler/rustc_middle/src/ty/significant_drop_order.rs index 2d9e0331451fd..4881d611c1282 100644 --- a/compiler/rustc_middle/src/ty/significant_drop_order.rs +++ b/compiler/rustc_middle/src/ty/significant_drop_order.rs @@ -154,7 +154,7 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option { let dtor = if let Some(dtor) = tcx.adt_destructor(did) { dtor.did } else if let Some(dtor) = tcx.adt_async_destructor(did) { - dtor.future + return Some(tcx.source_span(dtor.impl_did)); } else { return Some(try_local_did_span(did)); }; diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 7743e202aae43..50efb57586c4e 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -450,26 +450,17 @@ impl<'tcx> TyCtxt<'tcx> { continue; } - let [future, ctor] = self.associated_item_def_ids(impl_did) else { - self.dcx().span_delayed_bug( - self.def_span(impl_did), - "AsyncDrop impl without async_drop function or Dropper type", - ); - continue; - }; - - if let Some((_, _, old_impl_did)) = dtor_candidate { + if let Some(old_impl_did) = dtor_candidate { self.dcx() .struct_span_err(self.def_span(impl_did), "multiple async drop impls found") .with_span_note(self.def_span(old_impl_did), "other impl here") .delay_as_bug(); } - dtor_candidate = Some((*future, *ctor, impl_did)); + dtor_candidate = Some(impl_did); } - let (future, ctor, _) = dtor_candidate?; - Some(ty::AsyncDestructor { future, ctor }) + Some(ty::AsyncDestructor { impl_did: dtor_candidate? }) } /// Returns async drop glue morphology for a definition. To get async drop