Fix miscompilation when adding default method to Future

This commit is contained in:
Jonas Schievink 2023-05-08 16:04:20 +02:00
parent c86e7fb60f
commit 3bbb69eaa0

View File

@ -194,21 +194,18 @@ fn resolve_associated_item<'tcx>(
})
}
traits::ImplSource::Future(future_data) => {
if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::poll {
// For compiler developers who'd like to add new items to `Future`,
// you either need to generate a shim body, or perhaps return
// `InstanceDef::Item` pointing to a trait default method body if
// it is given a default implementation by the trait.
span_bug!(
tcx.def_span(future_data.generator_def_id),
"no definition for `{trait_ref}::{}` for built-in async generator type",
tcx.item_name(trait_item_id)
)
if Some(trait_item_id) == tcx.lang_items().future_poll_fn() {
// `Future::poll` is generated by the compiler.
Some(Instance {
def: ty::InstanceDef::Item(future_data.generator_def_id),
substs: future_data.substs,
})
} else {
// All other methods are default methods of the `Future` trait.
// (this assumes that `ImplSource::Future` is only used for methods on `Future`)
debug_assert!(tcx.impl_defaultness(trait_item_id).has_value());
Some(Instance::new(trait_item_id, rcvr_substs))
}
Some(Instance {
def: ty::InstanceDef::Item(future_data.generator_def_id),
substs: future_data.substs,
})
}
traits::ImplSource::Closure(closure_data) => {
if cfg!(debug_assertions)