@@ -47,7 +47,6 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro
4747
4848 ensure_drop_predicates_are_implied_by_item_defn (
4949 tcx,
50- drop_impl_did,
5150 dtor_predicates,
5251 adt_def. did ,
5352 self_to_impl_substs,
@@ -95,16 +94,23 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
9594 }
9695 Err ( _) => {
9796 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" ) ;
98101 struct_span_err ! (
99102 tcx. sess,
100103 drop_impl_span,
101104 E0366 ,
102- "Implementations of Drop cannot be specialized"
105+ "` Drop` impls cannot be specialized"
103106 )
104107 . span_note (
105108 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+ ) ,
108114 )
109115 . emit ( ) ;
110116 return Err ( ErrorReported ) ;
@@ -143,7 +149,6 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
143149/// implied by assuming the predicates attached to self_type_did.
144150fn ensure_drop_predicates_are_implied_by_item_defn < ' tcx > (
145151 tcx : TyCtxt < ' tcx > ,
146- drop_impl_did : DefId ,
147152 dtor_predicates : ty:: GenericPredicates < ' tcx > ,
148153 self_type_did : DefId ,
149154 self_to_impl_substs : SubstsRef < ' tcx > ,
@@ -187,8 +192,6 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
187192
188193 let self_type_hir_id = tcx. hir ( ) . as_local_hir_id ( self_type_did) . unwrap ( ) ;
189194
190- let drop_impl_span = tcx. def_span ( drop_impl_did) ;
191-
192195 // We can assume the predicates attached to struct/enum definition
193196 // hold.
194197 let generic_assumptions = tcx. predicates_of ( self_type_did) ;
@@ -205,7 +208,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
205208 // just to look for all the predicates directly.
206209
207210 assert_eq ! ( dtor_predicates. parent, None ) ;
208- for ( predicate, _ ) in dtor_predicates. predicates {
211+ for ( predicate, predicate_sp ) in dtor_predicates. predicates {
209212 // (We do not need to worry about deep analysis of type
210213 // expressions etc because the Drop impls are already forced
211214 // 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>(
241244
242245 if !assumptions_in_impl_context. iter ( ) . any ( predicate_matches_closure) {
243246 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" ) ;
244249 struct_span_err ! (
245250 tcx. sess,
246- drop_impl_span ,
251+ * predicate_sp ,
247252 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,
255256 )
257+ . span_note ( item_span, "the implementor must specify the same requirement" )
256258 . emit ( ) ;
257259 result = Err ( ErrorReported ) ;
258260 }
0 commit comments