@@ -25,14 +25,14 @@ use rustc_trait_selection::traits::ObligationCtxt;
2525use rustc_trait_selection:: traits:: { self , ObligationCause } ;
2626use std:: collections:: BTreeMap ;
2727
28- pub fn check_trait < ' tcx > (
28+ pub ( super ) fn check_trait < ' tcx > (
2929 tcx : TyCtxt < ' tcx > ,
3030 trait_def_id : DefId ,
3131 impl_def_id : LocalDefId ,
3232 impl_header : ty:: ImplTraitHeader < ' tcx > ,
3333) -> Result < ( ) , ErrorGuaranteed > {
3434 let lang_items = tcx. lang_items ( ) ;
35- let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header } ;
35+ let checker = Checker :: new ( tcx, trait_def_id, impl_def_id, impl_header) ;
3636 let mut res = checker. check ( lang_items. drop_trait ( ) , visit_implementation_of_drop) ;
3737 res = res. and ( checker. check ( lang_items. copy_trait ( ) , visit_implementation_of_copy) ) ;
3838 res = res. and (
@@ -52,9 +52,19 @@ struct Checker<'tcx> {
5252 trait_def_id : DefId ,
5353 impl_def_id : LocalDefId ,
5454 impl_header : ty:: ImplTraitHeader < ' tcx > ,
55+ trait_ref : ty:: TraitRef < ' tcx > ,
5556}
5657
5758impl < ' tcx > Checker < ' tcx > {
59+ fn new (
60+ tcx : TyCtxt < ' tcx > ,
61+ trait_def_id : DefId ,
62+ impl_def_id : LocalDefId ,
63+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
64+ ) -> Self {
65+ let trait_ref = impl_header. trait_ref . instantiate_identity ( ) ;
66+ Self { tcx, trait_def_id, impl_def_id, impl_header, trait_ref }
67+ }
5868 fn check (
5969 & self ,
6070 trait_def_id : Option < DefId > ,
@@ -66,10 +76,9 @@ impl<'tcx> Checker<'tcx> {
6676
6777fn visit_implementation_of_drop ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
6878 let tcx = checker. tcx ;
69- let header = checker. impl_header ;
7079 let impl_did = checker. impl_def_id ;
7180 // Destructors only work on local ADT types.
72- match header . trait_ref . self_ty ( ) . kind ( ) {
81+ match checker . trait_ref . self_ty ( ) . kind ( ) {
7382 ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => return Ok ( ( ) ) ,
7483 ty:: Error ( _) => return Ok ( ( ) ) ,
7584 _ => { }
@@ -86,7 +95,7 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
8695 let impl_did = checker. impl_def_id ;
8796 debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
8897
89- let self_type = impl_header . trait_ref . self_ty ( ) ;
98+ let self_type = checker . trait_ref . self_ty ( ) ;
9099 debug ! ( "visit_implementation_of_copy: self_type={:?} (bound)" , self_type) ;
91100
92101 let param_env = tcx. param_env ( impl_did) ;
@@ -120,7 +129,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
120129 let tcx = checker. tcx ;
121130 let header = checker. impl_header ;
122131 let impl_did = checker. impl_def_id ;
123- let self_type = header . trait_ref . self_ty ( ) ;
132+ let self_type = checker . trait_ref . self_ty ( ) ;
124133 assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
125134
126135 let param_env = tcx. param_env ( impl_did) ;
@@ -157,9 +166,8 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
157166
158167fn visit_implementation_of_dispatch_from_dyn ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
159168 let tcx = checker. tcx ;
160- let header = checker. impl_header ;
161169 let impl_did = checker. impl_def_id ;
162- let trait_ref = header . trait_ref ;
170+ let trait_ref = checker . trait_ref ;
163171 debug ! ( "visit_implementation_of_dispatch_from_dyn: impl_did={:?}" , impl_did) ;
164172
165173 let span = tcx. def_span ( impl_did) ;
0 commit comments