1
1
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
2
2
//
3
3
// We don't do any drop checking during hir typeck.
4
- use crate :: hir:: def_id:: { DefId , LocalDefId } ;
5
4
use rustc_errors:: { struct_span_err, ErrorGuaranteed } ;
6
5
use rustc_middle:: ty:: error:: TypeError ;
7
6
use rustc_middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
8
7
use rustc_middle:: ty:: subst:: SubstsRef ;
9
8
use rustc_middle:: ty:: util:: IgnoreRegions ;
10
9
use rustc_middle:: ty:: { self , Predicate , Ty , TyCtxt } ;
11
10
11
+ use crate :: errors;
12
+ use crate :: hir:: def_id:: { DefId , LocalDefId } ;
13
+
12
14
/// This function confirms that the `Drop` implementation identified by
13
15
/// `drop_impl_did` is not any more specialized than the type it is
14
16
/// attached to (Issue #8142).
@@ -27,6 +29,19 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
27
29
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
28
30
///
29
31
pub 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
+ }
30
45
let dtor_self_type = tcx. type_of ( drop_impl_did) . subst_identity ( ) ;
31
46
let dtor_predicates = tcx. predicates_of ( drop_impl_did) ;
32
47
match dtor_self_type. kind ( ) {
0 commit comments