@@ -25,10 +25,11 @@ use rustc_trait_selection::traits::ObligationCtxt;
25
25
use rustc_trait_selection:: traits:: { self , ObligationCause } ;
26
26
use std:: collections:: BTreeMap ;
27
27
28
- pub fn check_trait (
29
- tcx : TyCtxt < ' _ > ,
28
+ pub fn check_trait < ' tcx > (
29
+ tcx : TyCtxt < ' tcx > ,
30
30
trait_def_id : DefId ,
31
31
impl_def_id : LocalDefId ,
32
+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
32
33
) -> Result < ( ) , ErrorGuaranteed > {
33
34
let lang_items = tcx. lang_items ( ) ;
34
35
let checker = Checker { tcx, trait_def_id, impl_def_id } ;
@@ -40,10 +41,9 @@ pub fn check_trait(
40
41
res = res. and (
41
42
checker. check ( lang_items. coerce_unsized_trait ( ) , visit_implementation_of_coerce_unsized) ,
42
43
) ;
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
+ } ) )
47
47
}
48
48
49
49
struct Checker < ' tcx > {
@@ -151,20 +151,20 @@ fn visit_implementation_of_coerce_unsized(
151
151
tcx. at ( span) . ensure ( ) . coerce_unsized_info ( impl_did)
152
152
}
153
153
154
- fn visit_implementation_of_dispatch_from_dyn (
155
- tcx : TyCtxt < ' _ > ,
154
+ fn visit_implementation_of_dispatch_from_dyn < ' tcx > (
155
+ tcx : TyCtxt < ' tcx > ,
156
156
impl_did : LocalDefId ,
157
+ trait_ref : ty:: TraitRef < ' tcx > ,
157
158
) -> Result < ( ) , ErrorGuaranteed > {
158
159
debug ! ( "visit_implementation_of_dispatch_from_dyn: impl_did={:?}" , impl_did) ;
159
160
160
161
let span = tcx. def_span ( impl_did) ;
161
162
162
163
let dispatch_from_dyn_trait = tcx. require_lang_item ( LangItem :: DispatchFromDyn , Some ( span) ) ;
163
164
164
- let source = tcx . type_of ( impl_did ) . instantiate_identity ( ) ;
165
+ let source = trait_ref . self_ty ( ) ;
165
166
assert ! ( !source. has_escaping_bound_vars( ) ) ;
166
167
let target = {
167
- let trait_ref = tcx. impl_trait_ref ( impl_did) . unwrap ( ) . instantiate_identity ( ) ;
168
168
assert_eq ! ( trait_ref. def_id, dispatch_from_dyn_trait) ;
169
169
170
170
trait_ref. args . type_at ( 1 )
0 commit comments