@@ -47,7 +47,6 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro
47
47
48
48
ensure_drop_predicates_are_implied_by_item_defn (
49
49
tcx,
50
- drop_impl_did,
51
50
dtor_predicates,
52
51
adt_def. did ,
53
52
self_to_impl_substs,
@@ -95,16 +94,23 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
95
94
}
96
95
Err ( _) => {
97
96
let item_span = tcx. def_span ( self_type_did) ;
97
+ let self_descr = tcx
98
+ . def_kind ( self_type_did)
99
+ . map ( |kind| kind. descr ( self_type_did) )
100
+ . unwrap_or ( "type" ) ;
98
101
struct_span_err ! (
99
102
tcx. sess,
100
103
drop_impl_span,
101
104
E0366 ,
102
- "Implementations of Drop cannot be specialized"
105
+ "` Drop` impls cannot be specialized"
103
106
)
104
107
. span_note (
105
108
item_span,
106
- "Use same sequence of generic type and region \
107
- parameters that is on the struct/enum definition",
109
+ & format ! (
110
+ "use the same sequence of generic type, lifetime and const parameters \
111
+ as the {} definition",
112
+ self_descr,
113
+ ) ,
108
114
)
109
115
. emit ( ) ;
110
116
return Err ( ErrorReported ) ;
@@ -143,7 +149,6 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
143
149
/// implied by assuming the predicates attached to self_type_did.
144
150
fn ensure_drop_predicates_are_implied_by_item_defn < ' tcx > (
145
151
tcx : TyCtxt < ' tcx > ,
146
- drop_impl_did : DefId ,
147
152
dtor_predicates : ty:: GenericPredicates < ' tcx > ,
148
153
self_type_did : DefId ,
149
154
self_to_impl_substs : SubstsRef < ' tcx > ,
@@ -187,8 +192,6 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
187
192
188
193
let self_type_hir_id = tcx. hir ( ) . as_local_hir_id ( self_type_did) . unwrap ( ) ;
189
194
190
- let drop_impl_span = tcx. def_span ( drop_impl_did) ;
191
-
192
195
// We can assume the predicates attached to struct/enum definition
193
196
// hold.
194
197
let generic_assumptions = tcx. predicates_of ( self_type_did) ;
@@ -205,7 +208,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
205
208
// just to look for all the predicates directly.
206
209
207
210
assert_eq ! ( dtor_predicates. parent, None ) ;
208
- for ( predicate, _ ) in dtor_predicates. predicates {
211
+ for ( predicate, predicate_sp ) in dtor_predicates. predicates {
209
212
// (We do not need to worry about deep analysis of type
210
213
// expressions etc because the Drop impls are already forced
211
214
// to take on a structure that is roughly an alpha-renaming of
@@ -241,18 +244,17 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
241
244
242
245
if !assumptions_in_impl_context. iter ( ) . any ( predicate_matches_closure) {
243
246
let item_span = tcx. hir ( ) . span ( self_type_hir_id) ;
247
+ let self_descr =
248
+ tcx. def_kind ( self_type_did) . map ( |kind| kind. descr ( self_type_did) ) . unwrap_or ( "type" ) ;
244
249
struct_span_err ! (
245
250
tcx. sess,
246
- drop_impl_span ,
251
+ * predicate_sp ,
247
252
E0367 ,
248
- "The requirement `{}` is added only by the Drop impl." ,
249
- predicate
250
- )
251
- . span_note (
252
- item_span,
253
- "The same requirement must be part of \
254
- the struct/enum definition",
253
+ "`Drop` impl requires `{}` but the {} it is implemented for does not" ,
254
+ predicate,
255
+ self_descr,
255
256
)
257
+ . span_note ( item_span, "the implementor must specify the same requirement" )
256
258
. emit ( ) ;
257
259
result = Err ( ErrorReported ) ;
258
260
}
0 commit comments