Skip to content

Commit a2618e1

Browse files
committed
AsyncDestructor: replace fields with impl_did
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.
1 parent 00095b3 commit a2618e1

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

compiler/rustc_middle/src/ty/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,8 @@ pub struct Destructor {
11241124
// FIXME: consider combining this definition with regular `Destructor`
11251125
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
11261126
pub struct AsyncDestructor {
1127-
/// The `DefId` of the async destructor future constructor
1128-
pub ctor: DefId,
1129-
/// The `DefId` of the async destructor future type
1130-
pub future: DefId,
1127+
/// The `DefId` of the `impl AsyncDrop`
1128+
pub impl_did: LocalDefId,
11311129
}
11321130

11331131
#[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_middle/src/ty/significant_drop_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> {
154154
let dtor = if let Some(dtor) = tcx.adt_destructor(did) {
155155
dtor.did
156156
} else if let Some(dtor) = tcx.adt_async_destructor(did) {
157-
dtor.future
157+
return Some(tcx.source_span(dtor.impl_did));
158158
} else {
159159
return Some(try_local_did_span(did));
160160
};

compiler/rustc_middle/src/ty/util.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -450,26 +450,17 @@ impl<'tcx> TyCtxt<'tcx> {
450450
continue;
451451
}
452452

453-
let [future, ctor] = self.associated_item_def_ids(impl_did) else {
454-
self.dcx().span_delayed_bug(
455-
self.def_span(impl_did),
456-
"AsyncDrop impl without async_drop function or Dropper type",
457-
);
458-
continue;
459-
};
460-
461-
if let Some((_, _, old_impl_did)) = dtor_candidate {
453+
if let Some(old_impl_did) = dtor_candidate {
462454
self.dcx()
463455
.struct_span_err(self.def_span(impl_did), "multiple async drop impls found")
464456
.with_span_note(self.def_span(old_impl_did), "other impl here")
465457
.delay_as_bug();
466458
}
467459

468-
dtor_candidate = Some((*future, *ctor, impl_did));
460+
dtor_candidate = Some(impl_did);
469461
}
470462

471-
let (future, ctor, _) = dtor_candidate?;
472-
Some(ty::AsyncDestructor { future, ctor })
463+
Some(ty::AsyncDestructor { impl_did: dtor_candidate? })
473464
}
474465

475466
/// Returns async drop glue morphology for a definition. To get async drop

0 commit comments

Comments
 (0)