diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index ec577072e19..eb3c21163ab 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -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)