Fix miscompilation when adding default method to Future
This commit is contained in:
parent
c86e7fb60f
commit
3bbb69eaa0
@ -194,21 +194,18 @@ fn resolve_associated_item<'tcx>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
traits::ImplSource::Future(future_data) => {
|
traits::ImplSource::Future(future_data) => {
|
||||||
if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::poll {
|
if Some(trait_item_id) == tcx.lang_items().future_poll_fn() {
|
||||||
// For compiler developers who'd like to add new items to `Future`,
|
// `Future::poll` is generated by the compiler.
|
||||||
// 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)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Some(Instance {
|
Some(Instance {
|
||||||
def: ty::InstanceDef::Item(future_data.generator_def_id),
|
def: ty::InstanceDef::Item(future_data.generator_def_id),
|
||||||
substs: future_data.substs,
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
traits::ImplSource::Closure(closure_data) => {
|
traits::ImplSource::Closure(closure_data) => {
|
||||||
if cfg!(debug_assertions)
|
if cfg!(debug_assertions)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user