@@ -32,45 +32,42 @@ pub fn check_trait<'tcx>(
32
32
impl_header : ty:: ImplTraitHeader < ' tcx > ,
33
33
) -> Result < ( ) , ErrorGuaranteed > {
34
34
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
+ ) ;
45
41
res = res. and (
46
42
checker. check ( lang_items. coerce_unsized_trait ( ) , visit_implementation_of_coerce_unsized) ,
47
43
) ;
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
+ )
51
48
}
52
49
53
50
struct Checker < ' tcx > {
54
51
tcx : TyCtxt < ' tcx > ,
55
52
trait_def_id : DefId ,
56
53
impl_def_id : LocalDefId ,
54
+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
57
55
}
58
56
59
57
impl < ' tcx > Checker < ' tcx > {
60
58
fn check (
61
59
& self ,
62
60
trait_def_id : Option < DefId > ,
63
- f : impl FnOnce ( TyCtxt < ' tcx > , LocalDefId ) -> Result < ( ) , ErrorGuaranteed > ,
61
+ f : impl FnOnce ( & Self ) -> Result < ( ) , ErrorGuaranteed > ,
64
62
) -> 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 ( ( ) ) }
66
64
}
67
65
}
68
66
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 ;
74
71
// Destructors only work on local ADT types.
75
72
match header. trait_ref . self_ty ( ) . kind ( ) {
76
73
ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => return Ok ( ( ) ) ,
@@ -83,11 +80,10 @@ fn visit_implementation_of_drop<'tcx>(
83
80
Err ( tcx. dcx ( ) . emit_err ( errors:: DropImplOnWrongItem { span : impl_. self_ty . span } ) )
84
81
}
85
82
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 ;
91
87
debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
92
88
93
89
let self_type = impl_header. trait_ref . self_ty ( ) ;
@@ -120,11 +116,10 @@ fn visit_implementation_of_copy<'tcx>(
120
116
}
121
117
}
122
118
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 ;
128
123
let self_type = header. trait_ref . self_ty ( ) ;
129
124
assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
130
125
@@ -148,10 +143,9 @@ fn visit_implementation_of_const_param_ty<'tcx>(
148
143
}
149
144
}
150
145
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 ;
155
149
debug ! ( "visit_implementation_of_coerce_unsized: impl_did={:?}" , impl_did) ;
156
150
157
151
// Just compute this for the side-effects, in particular reporting
@@ -161,11 +155,11 @@ fn visit_implementation_of_coerce_unsized(
161
155
tcx. at ( span) . ensure ( ) . coerce_unsized_info ( impl_did)
162
156
}
163
157
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 ;
169
163
debug ! ( "visit_implementation_of_dispatch_from_dyn: impl_did={:?}" , impl_did) ;
170
164
171
165
let span = tcx. def_span ( impl_did) ;
0 commit comments