11// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
22//
33// We don't do any drop checking during hir typeck.
4- use crate :: hir:: def_id:: { DefId , LocalDefId } ;
54use rustc_errors:: { struct_span_err, ErrorGuaranteed } ;
65use rustc_middle:: ty:: error:: TypeError ;
76use rustc_middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
87use rustc_middle:: ty:: subst:: SubstsRef ;
98use rustc_middle:: ty:: util:: IgnoreRegions ;
109use rustc_middle:: ty:: { self , Predicate , Ty , TyCtxt } ;
1110
11+ use crate :: errors;
12+ use crate :: hir:: def_id:: { DefId , LocalDefId } ;
13+
1214/// This function confirms that the `Drop` implementation identified by
1315/// `drop_impl_did` is not any more specialized than the type it is
1416/// attached to (Issue #8142).
@@ -27,6 +29,19 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
2729/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
2830///
2931pub fn check_drop_impl ( tcx : TyCtxt < ' _ > , drop_impl_did : DefId ) -> Result < ( ) , ErrorGuaranteed > {
32+ match tcx. impl_polarity ( drop_impl_did) {
33+ ty:: ImplPolarity :: Positive => { }
34+ ty:: ImplPolarity :: Negative => {
35+ return Err ( tcx. sess . emit_err ( errors:: DropImplPolarity :: Negative {
36+ span : tcx. def_span ( drop_impl_did) ,
37+ } ) ) ;
38+ }
39+ ty:: ImplPolarity :: Reservation => {
40+ return Err ( tcx. sess . emit_err ( errors:: DropImplPolarity :: Reservation {
41+ span : tcx. def_span ( drop_impl_did) ,
42+ } ) ) ;
43+ }
44+ }
3045 let dtor_self_type = tcx. type_of ( drop_impl_did) . subst_identity ( ) ;
3146 let dtor_predicates = tcx. predicates_of ( drop_impl_did) ;
3247 match dtor_self_type. kind ( ) {
0 commit comments