@@ -10,8 +10,8 @@ use rustc_hir as hir;
1010use rustc_hir:: LangItem ;
1111use rustc_middle:: bug;
1212use rustc_middle:: ty:: {
13- self , ExistentialPredicateStableCmpExt as _, Instance , InstanceKind , IntTy , List , TraitRef , Ty ,
14- TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt , UintTy ,
13+ self , ExistentialPredicateStableCmpExt as _, Instance , IntTy , List , TraitRef , Ty , TyCtxt ,
14+ TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt , UintTy ,
1515} ;
1616use rustc_span:: def_id:: DefId ;
1717use rustc_span:: { DUMMY_SP , sym} ;
@@ -453,40 +453,20 @@ pub(crate) fn transform_instance<'tcx>(
453453 instance. def = ty:: InstanceKind :: Virtual ( call, 0 ) ;
454454 instance. args = abstract_args;
455455 }
456- let fn_traits = [
457- ( LangItem :: Fn , sym:: call) ,
458- ( LangItem :: FnMut , sym:: call_mut) ,
459- ( LangItem :: FnOnce , sym:: call_once) ,
460- ] ;
461- for ( lang_item, method_sym) in fn_traits {
462- if let Some ( trait_id) = tcx. lang_items ( ) . get ( lang_item) {
463- let items = tcx. associated_items ( trait_id) ;
464- if let Some ( call_method) =
465- items. in_definition_order ( ) . find ( |item| item. name ( ) == method_sym)
466- {
467- if instance. def_id ( ) == call_method. def_id {
468- // This is a call to a method of Fn, FnMut, or FnOnce. Transform self into a
469- // trait object of the trait that defines the method.
470- let self_ty = trait_object_ty (
471- tcx,
472- ty:: Binder :: dummy ( ty:: TraitRef :: from_method (
473- tcx,
474- trait_id,
475- instance. args ,
476- ) ) ,
477- ) ;
478- instance. args =
479- tcx. mk_args_trait ( self_ty, instance. args . into_iter ( ) . skip ( 1 ) ) ;
480- break ;
481- }
482- }
483- }
484- }
485456 }
486457
487458 instance
488459}
489460
461+ fn default_or_shim < ' tcx > ( instance : Instance < ' tcx > ) -> Option < DefId > {
462+ match instance. def {
463+ ty:: InstanceKind :: Item ( def_id) | ty:: InstanceKind :: FnPtrShim ( def_id, _) => {
464+ tcx. opt_associated_item ( def_id)
465+ }
466+ _ => None ,
467+ }
468+ }
469+
490470fn implemented_method < ' tcx > (
491471 tcx : TyCtxt < ' tcx > ,
492472 instance : Instance < ' tcx > ,
@@ -503,10 +483,8 @@ fn implemented_method<'tcx>(
503483 trait_method = tcx. associated_item ( method_id) ;
504484 trait_id = trait_ref. skip_binder ( ) . def_id ;
505485 impl_id
506- } else if let InstanceKind :: Item ( def_id) = instance. def
507- && let Some ( trait_method_bound) = tcx. opt_associated_item ( def_id)
508- {
509- // Provided method in a `trait` block
486+ } else if let Some ( trait_method_bound) = default_or_shim ( instance) {
487+ // Provided method in a `trait` block or a synthetic `shim`
510488 trait_method = trait_method_bound;
511489 method_id = instance. def_id ( ) ;
512490 trait_id = tcx. trait_of_assoc ( method_id) ?;
0 commit comments