@@ -25,10 +25,11 @@ use rustc_trait_selection::traits::ObligationCtxt;
2525use rustc_trait_selection:: traits:: { self , ObligationCause } ;
2626use std:: collections:: BTreeMap ;
2727
28- pub fn check_trait (
29- tcx : TyCtxt < ' _ > ,
28+ pub fn check_trait < ' tcx > (
29+ tcx : TyCtxt < ' tcx > ,
3030 trait_def_id : DefId ,
3131 impl_def_id : LocalDefId ,
32+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
3233) -> Result < ( ) , ErrorGuaranteed > {
3334 let lang_items = tcx. lang_items ( ) ;
3435 let checker = Checker { tcx, trait_def_id, impl_def_id } ;
@@ -40,10 +41,9 @@ pub fn check_trait(
4041 res = res. and (
4142 checker. check ( lang_items. coerce_unsized_trait ( ) , visit_implementation_of_coerce_unsized) ,
4243 ) ;
43- res. and (
44- checker
45- . check ( lang_items. dispatch_from_dyn_trait ( ) , visit_implementation_of_dispatch_from_dyn) ,
46- )
44+ res. and ( checker. check ( lang_items. dispatch_from_dyn_trait ( ) , |tcx, id| {
45+ visit_implementation_of_dispatch_from_dyn ( tcx, id, impl_header. trait_ref )
46+ } ) )
4747}
4848
4949struct Checker < ' tcx > {
@@ -151,20 +151,20 @@ fn visit_implementation_of_coerce_unsized(
151151 tcx. at ( span) . ensure ( ) . coerce_unsized_info ( impl_did)
152152}
153153
154- fn visit_implementation_of_dispatch_from_dyn (
155- tcx : TyCtxt < ' _ > ,
154+ fn visit_implementation_of_dispatch_from_dyn < ' tcx > (
155+ tcx : TyCtxt < ' tcx > ,
156156 impl_did : LocalDefId ,
157+ trait_ref : ty:: TraitRef < ' tcx > ,
157158) -> Result < ( ) , ErrorGuaranteed > {
158159 debug ! ( "visit_implementation_of_dispatch_from_dyn: impl_did={:?}" , impl_did) ;
159160
160161 let span = tcx. def_span ( impl_did) ;
161162
162163 let dispatch_from_dyn_trait = tcx. require_lang_item ( LangItem :: DispatchFromDyn , Some ( span) ) ;
163164
164- let source = tcx . type_of ( impl_did ) . instantiate_identity ( ) ;
165+ let source = trait_ref . self_ty ( ) ;
165166 assert ! ( !source. has_escaping_bound_vars( ) ) ;
166167 let target = {
167- let trait_ref = tcx. impl_trait_ref ( impl_did) . unwrap ( ) . instantiate_identity ( ) ;
168168 assert_eq ! ( trait_ref. def_id, dispatch_from_dyn_trait) ;
169169
170170 trait_ref. args . type_at ( 1 )
0 commit comments