@@ -177,83 +177,6 @@ fn resolve_associated_item<'tcx>(
177177
178178 Some ( ty:: Instance :: new ( leaf_def. item . def_id , substs) )
179179 }
180- traits:: ImplSource :: Generator ( _) => {
181- let ty:: Generator ( generator_def_id, substs, _) = * rcvr_substs. type_at ( 0 ) . kind ( ) else {
182- unreachable ! ( )
183- } ;
184- if cfg ! ( debug_assertions) && tcx. item_name ( trait_item_id) != sym:: resume {
185- // For compiler developers who'd like to add new items to `Generator`,
186- // you either need to generate a shim body, or perhaps return
187- // `InstanceDef::Item` pointing to a trait default method body if
188- // it is given a default implementation by the trait.
189- span_bug ! (
190- tcx. def_span( generator_def_id) ,
191- "no definition for `{trait_ref}::{}` for built-in generator type" ,
192- tcx. item_name( trait_item_id)
193- )
194- }
195- Some ( Instance { def : ty:: InstanceDef :: Item ( generator_def_id) , substs } )
196- }
197- traits:: ImplSource :: Future ( _) => {
198- let ty:: Generator ( generator_def_id, substs, _) = * rcvr_substs. type_at ( 0 ) . kind ( ) else {
199- unreachable ! ( )
200- } ;
201- if Some ( trait_item_id) == tcx. lang_items ( ) . future_poll_fn ( ) {
202- // `Future::poll` is generated by the compiler.
203- Some ( Instance { def : ty:: InstanceDef :: Item ( generator_def_id) , substs : substs } )
204- } else {
205- // All other methods are default methods of the `Future` trait.
206- // (this assumes that `ImplSource::Future` is only used for methods on `Future`)
207- debug_assert ! ( tcx. defaultness( trait_item_id) . has_value( ) ) ;
208- Some ( Instance :: new ( trait_item_id, rcvr_substs) )
209- }
210- }
211- traits:: ImplSource :: Closure ( _) => {
212- let ty:: Closure ( closure_def_id, substs) = * rcvr_substs. type_at ( 0 ) . kind ( ) else {
213- unreachable ! ( )
214- } ;
215- if cfg ! ( debug_assertions)
216- && ![ sym:: call, sym:: call_mut, sym:: call_once]
217- . contains ( & tcx. item_name ( trait_item_id) )
218- {
219- // For compiler developers who'd like to add new items to `Fn`/`FnMut`/`FnOnce`,
220- // you either need to generate a shim body, or perhaps return
221- // `InstanceDef::Item` pointing to a trait default method body if
222- // it is given a default implementation by the trait.
223- span_bug ! (
224- tcx. def_span( closure_def_id) ,
225- "no definition for `{trait_ref}::{}` for built-in closure type" ,
226- tcx. item_name( trait_item_id)
227- )
228- }
229- let trait_closure_kind = tcx. fn_trait_kind_from_def_id ( trait_id) . unwrap ( ) ;
230- Instance :: resolve_closure ( tcx, closure_def_id, substs, trait_closure_kind)
231- }
232- traits:: ImplSource :: FnPointer ( _) => match rcvr_substs. type_at ( 0 ) . kind ( ) {
233- ty:: FnDef ( ..) | ty:: FnPtr ( ..) => {
234- if cfg ! ( debug_assertions)
235- && ![ sym:: call, sym:: call_mut, sym:: call_once]
236- . contains ( & tcx. item_name ( trait_item_id) )
237- {
238- // For compiler developers who'd like to add new items to `Fn`/`FnMut`/`FnOnce`,
239- // you either need to generate a shim body, or perhaps return
240- // `InstanceDef::Item` pointing to a trait default method body if
241- // it is given a default implementation by the trait.
242- bug ! (
243- "no definition for `{trait_ref}::{}` for built-in fn type" ,
244- tcx. item_name( trait_item_id)
245- )
246- }
247- Some ( Instance {
248- def : ty:: InstanceDef :: FnPtrShim ( trait_item_id, rcvr_substs. type_at ( 0 ) ) ,
249- substs : rcvr_substs,
250- } )
251- }
252- _ => bug ! (
253- "no built-in definition for `{trait_ref}::{}` for non-fn type" ,
254- tcx. item_name( trait_item_id)
255- ) ,
256- } ,
257180 traits:: ImplSource :: Object ( ref data) => {
258181 traits:: get_vtable_index_of_object_method ( tcx, data, trait_item_id) . map ( |index| {
259182 Instance {
@@ -306,6 +229,66 @@ fn resolve_associated_item<'tcx>(
306229 span : tcx. def_span ( trait_item_id) ,
307230 } )
308231 }
232+ } else if Some ( trait_ref. def_id ) == lang_items. future_trait ( ) {
233+ let ty:: Generator ( generator_def_id, substs, _) = * rcvr_substs. type_at ( 0 ) . kind ( ) else {
234+ bug ! ( )
235+ } ;
236+ if Some ( trait_item_id) == tcx. lang_items ( ) . future_poll_fn ( ) {
237+ // `Future::poll` is generated by the compiler.
238+ Some ( Instance { def : ty:: InstanceDef :: Item ( generator_def_id) , substs : substs } )
239+ } else {
240+ // All other methods are default methods of the `Future` trait.
241+ // (this assumes that `ImplSource::Builtin` is only used for methods on `Future`)
242+ debug_assert ! ( tcx. defaultness( trait_item_id) . has_value( ) ) ;
243+ Some ( Instance :: new ( trait_item_id, rcvr_substs) )
244+ }
245+ } else if Some ( trait_ref. def_id ) == lang_items. gen_trait ( ) {
246+ let ty:: Generator ( generator_def_id, substs, _) = * rcvr_substs. type_at ( 0 ) . kind ( ) else {
247+ bug ! ( )
248+ } ;
249+ if cfg ! ( debug_assertions) && tcx. item_name ( trait_item_id) != sym:: resume {
250+ // For compiler developers who'd like to add new items to `Generator`,
251+ // you either need to generate a shim body, or perhaps return
252+ // `InstanceDef::Item` pointing to a trait default method body if
253+ // it is given a default implementation by the trait.
254+ span_bug ! (
255+ tcx. def_span( generator_def_id) ,
256+ "no definition for `{trait_ref}::{}` for built-in generator type" ,
257+ tcx. item_name( trait_item_id)
258+ )
259+ }
260+ Some ( Instance { def : ty:: InstanceDef :: Item ( generator_def_id) , substs } )
261+ } else if tcx. fn_trait_kind_from_def_id ( trait_ref. def_id ) . is_some ( ) {
262+ // FIXME: This doesn't check for malformed libcore that defines, e.g.,
263+ // `trait Fn { fn call_once(&self) { .. } }`. This is mostly for extension
264+ // methods.
265+ if cfg ! ( debug_assertions)
266+ && ![ sym:: call, sym:: call_mut, sym:: call_once]
267+ . contains ( & tcx. item_name ( trait_item_id) )
268+ {
269+ // For compiler developers who'd like to add new items to `Fn`/`FnMut`/`FnOnce`,
270+ // you either need to generate a shim body, or perhaps return
271+ // `InstanceDef::Item` pointing to a trait default method body if
272+ // it is given a default implementation by the trait.
273+ bug ! (
274+ "no definition for `{trait_ref}::{}` for built-in callable type" ,
275+ tcx. item_name( trait_item_id)
276+ )
277+ }
278+ match * rcvr_substs. type_at ( 0 ) . kind ( ) {
279+ ty:: Closure ( closure_def_id, substs) => {
280+ let trait_closure_kind = tcx. fn_trait_kind_from_def_id ( trait_id) . unwrap ( ) ;
281+ Instance :: resolve_closure ( tcx, closure_def_id, substs, trait_closure_kind)
282+ }
283+ ty:: FnDef ( ..) | ty:: FnPtr ( ..) => Some ( Instance {
284+ def : ty:: InstanceDef :: FnPtrShim ( trait_item_id, rcvr_substs. type_at ( 0 ) ) ,
285+ substs : rcvr_substs,
286+ } ) ,
287+ _ => bug ! (
288+ "no built-in definition for `{trait_ref}::{}` for non-fn type" ,
289+ tcx. item_name( trait_item_id)
290+ ) ,
291+ }
309292 } else {
310293 None
311294 }
0 commit comments