@@ -33,11 +33,15 @@ pub fn check_trait<'tcx>(
33
33
) -> Result < ( ) , ErrorGuaranteed > {
34
34
let lang_items = tcx. lang_items ( ) ;
35
35
let checker = Checker { tcx, trait_def_id, impl_def_id } ;
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
- ) ;
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
+ } ) ) ;
41
45
res = res. and (
42
46
checker. check ( lang_items. coerce_unsized_trait ( ) , visit_implementation_of_coerce_unsized) ,
43
47
) ;
@@ -62,12 +66,13 @@ impl<'tcx> Checker<'tcx> {
62
66
}
63
67
}
64
68
65
- fn visit_implementation_of_drop (
66
- tcx : TyCtxt < ' _ > ,
69
+ fn visit_implementation_of_drop < ' tcx > (
70
+ tcx : TyCtxt < ' tcx > ,
67
71
impl_did : LocalDefId ,
72
+ header : ty:: ImplTraitHeader < ' tcx > ,
68
73
) -> Result < ( ) , ErrorGuaranteed > {
69
74
// Destructors only work on local ADT types.
70
- match tcx . type_of ( impl_did ) . instantiate_identity ( ) . kind ( ) {
75
+ match header . trait_ref . self_ty ( ) . kind ( ) {
71
76
ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => return Ok ( ( ) ) ,
72
77
ty:: Error ( _) => return Ok ( ( ) ) ,
73
78
_ => { }
@@ -78,21 +83,22 @@ fn visit_implementation_of_drop(
78
83
Err ( tcx. dcx ( ) . emit_err ( errors:: DropImplOnWrongItem { span : impl_. self_ty . span } ) )
79
84
}
80
85
81
- fn visit_implementation_of_copy (
82
- tcx : TyCtxt < ' _ > ,
86
+ fn visit_implementation_of_copy < ' tcx > (
87
+ tcx : TyCtxt < ' tcx > ,
83
88
impl_did : LocalDefId ,
89
+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
84
90
) -> Result < ( ) , ErrorGuaranteed > {
85
91
debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
86
92
87
- let self_type = tcx . type_of ( impl_did ) . instantiate_identity ( ) ;
93
+ let self_type = impl_header . trait_ref . self_ty ( ) ;
88
94
debug ! ( "visit_implementation_of_copy: self_type={:?} (bound)" , self_type) ;
89
95
90
96
let param_env = tcx. param_env ( impl_did) ;
91
97
assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
92
98
93
99
debug ! ( "visit_implementation_of_copy: self_type={:?} (free)" , self_type) ;
94
100
95
- if let ty:: ImplPolarity :: Negative = tcx . impl_polarity ( impl_did ) {
101
+ if let ty:: ImplPolarity :: Negative = impl_header . polarity {
96
102
return Ok ( ( ) ) ;
97
103
}
98
104
@@ -114,16 +120,17 @@ fn visit_implementation_of_copy(
114
120
}
115
121
}
116
122
117
- fn visit_implementation_of_const_param_ty (
118
- tcx : TyCtxt < ' _ > ,
123
+ fn visit_implementation_of_const_param_ty < ' tcx > (
124
+ tcx : TyCtxt < ' tcx > ,
119
125
impl_did : LocalDefId ,
126
+ header : ty:: ImplTraitHeader < ' tcx > ,
120
127
) -> Result < ( ) , ErrorGuaranteed > {
121
- let self_type = tcx . type_of ( impl_did ) . instantiate_identity ( ) ;
128
+ let self_type = header . trait_ref . self_ty ( ) ;
122
129
assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
123
130
124
131
let param_env = tcx. param_env ( impl_did) ;
125
132
126
- if let ty:: ImplPolarity :: Negative = tcx . impl_polarity ( impl_did ) {
133
+ if let ty:: ImplPolarity :: Negative = header . polarity {
127
134
return Ok ( ( ) ) ;
128
135
}
129
136
0 commit comments