@@ -32,45 +32,42 @@ pub fn check_trait<'tcx>(
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 } ;
36- let mut res = checker. check ( lang_items. drop_trait ( ) , |tcx, id| {
37- visit_implementation_of_drop ( tcx, id, impl_header)
38- } ) ;
39- res = res. and ( checker. check ( lang_items. copy_trait ( ) , |tcx, id| {
40- visit_implementation_of_copy ( tcx, id, impl_header)
41- } ) ) ;
42- res = res. and ( checker. check ( lang_items. const_param_ty_trait ( ) , |tcx, id| {
43- visit_implementation_of_const_param_ty ( tcx, id, impl_header)
44- } ) ) ;
35+ let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header } ;
36+ let mut res = checker. check ( lang_items. drop_trait ( ) , visit_implementation_of_drop) ;
37+ res = res. and ( checker. check ( lang_items. copy_trait ( ) , visit_implementation_of_copy) ) ;
38+ res = res. and (
39+ checker. check ( lang_items. const_param_ty_trait ( ) , visit_implementation_of_const_param_ty) ,
40+ ) ;
4541 res = res. and (
4642 checker. check ( lang_items. coerce_unsized_trait ( ) , visit_implementation_of_coerce_unsized) ,
4743 ) ;
48- res. and ( checker. check ( lang_items. dispatch_from_dyn_trait ( ) , |tcx, id| {
49- visit_implementation_of_dispatch_from_dyn ( tcx, id, impl_header. trait_ref )
50- } ) )
44+ res. and (
45+ checker
46+ . check ( lang_items. dispatch_from_dyn_trait ( ) , visit_implementation_of_dispatch_from_dyn) ,
47+ )
5148}
5249
5350struct Checker < ' tcx > {
5451 tcx : TyCtxt < ' tcx > ,
5552 trait_def_id : DefId ,
5653 impl_def_id : LocalDefId ,
54+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
5755}
5856
5957impl < ' tcx > Checker < ' tcx > {
6058 fn check (
6159 & self ,
6260 trait_def_id : Option < DefId > ,
63- f : impl FnOnce ( TyCtxt < ' tcx > , LocalDefId ) -> Result < ( ) , ErrorGuaranteed > ,
61+ f : impl FnOnce ( & Self ) -> Result < ( ) , ErrorGuaranteed > ,
6462 ) -> Result < ( ) , ErrorGuaranteed > {
65- if Some ( self . trait_def_id ) == trait_def_id { f ( self . tcx , self . impl_def_id ) } else { Ok ( ( ) ) }
63+ if Some ( self . trait_def_id ) == trait_def_id { f ( self ) } else { Ok ( ( ) ) }
6664 }
6765}
6866
69- fn visit_implementation_of_drop < ' tcx > (
70- tcx : TyCtxt < ' tcx > ,
71- impl_did : LocalDefId ,
72- header : ty:: ImplTraitHeader < ' tcx > ,
73- ) -> Result < ( ) , ErrorGuaranteed > {
67+ fn visit_implementation_of_drop ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
68+ let tcx = checker. tcx ;
69+ let header = checker. impl_header ;
70+ let impl_did = checker. impl_def_id ;
7471 // Destructors only work on local ADT types.
7572 match header. trait_ref . self_ty ( ) . kind ( ) {
7673 ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => return Ok ( ( ) ) ,
@@ -83,11 +80,10 @@ fn visit_implementation_of_drop<'tcx>(
8380 Err ( tcx. dcx ( ) . emit_err ( errors:: DropImplOnWrongItem { span : impl_. self_ty . span } ) )
8481}
8582
86- fn visit_implementation_of_copy < ' tcx > (
87- tcx : TyCtxt < ' tcx > ,
88- impl_did : LocalDefId ,
89- impl_header : ty:: ImplTraitHeader < ' tcx > ,
90- ) -> Result < ( ) , ErrorGuaranteed > {
83+ fn visit_implementation_of_copy ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
84+ let tcx = checker. tcx ;
85+ let impl_header = checker. impl_header ;
86+ let impl_did = checker. impl_def_id ;
9187 debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
9288
9389 let self_type = impl_header. trait_ref . self_ty ( ) ;
@@ -120,11 +116,10 @@ fn visit_implementation_of_copy<'tcx>(
120116 }
121117}
122118
123- fn visit_implementation_of_const_param_ty < ' tcx > (
124- tcx : TyCtxt < ' tcx > ,
125- impl_did : LocalDefId ,
126- header : ty:: ImplTraitHeader < ' tcx > ,
127- ) -> Result < ( ) , ErrorGuaranteed > {
119+ fn visit_implementation_of_const_param_ty ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
120+ let tcx = checker. tcx ;
121+ let header = checker. impl_header ;
122+ let impl_did = checker. impl_def_id ;
128123 let self_type = header. trait_ref . self_ty ( ) ;
129124 assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
130125
@@ -148,10 +143,9 @@ fn visit_implementation_of_const_param_ty<'tcx>(
148143 }
149144}
150145
151- fn visit_implementation_of_coerce_unsized (
152- tcx : TyCtxt < ' _ > ,
153- impl_did : LocalDefId ,
154- ) -> Result < ( ) , ErrorGuaranteed > {
146+ fn visit_implementation_of_coerce_unsized ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
147+ let tcx = checker. tcx ;
148+ let impl_did = checker. impl_def_id ;
155149 debug ! ( "visit_implementation_of_coerce_unsized: impl_did={:?}" , impl_did) ;
156150
157151 // Just compute this for the side-effects, in particular reporting
@@ -161,11 +155,11 @@ fn visit_implementation_of_coerce_unsized(
161155 tcx. at ( span) . ensure ( ) . coerce_unsized_info ( impl_did)
162156}
163157
164- fn visit_implementation_of_dispatch_from_dyn < ' tcx > (
165- tcx : TyCtxt < ' tcx > ,
166- impl_did : LocalDefId ,
167- trait_ref : ty :: TraitRef < ' tcx > ,
168- ) -> Result < ( ) , ErrorGuaranteed > {
158+ fn visit_implementation_of_dispatch_from_dyn ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
159+ let tcx = checker . tcx ;
160+ let header = checker . impl_header ;
161+ let impl_did = checker . impl_def_id ;
162+ let trait_ref = header . trait_ref ;
169163 debug ! ( "visit_implementation_of_dispatch_from_dyn: impl_did={:?}" , impl_did) ;
170164
171165 let span = tcx. def_span ( impl_did) ;
0 commit comments