@@ -33,6 +33,7 @@ use super::FnCtxt;
33
33
use crate :: type_error_struct;
34
34
use rustc_errors:: { struct_span_err, Applicability , DelayDm , DiagnosticBuilder , ErrorGuaranteed } ;
35
35
use rustc_hir as hir;
36
+ use rustc_macros:: { TypeFoldable , TypeVisitable } ;
36
37
use rustc_middle:: mir:: Mutability ;
37
38
use rustc_middle:: ty:: adjustment:: AllowTwoPhase ;
38
39
use rustc_middle:: ty:: cast:: { CastKind , CastTy } ;
@@ -65,7 +66,7 @@ pub struct CastCheck<'tcx> {
65
66
/// The kind of pointer and associated metadata (thin, length or vtable) - we
66
67
/// only allow casts between fat pointers if their metadata have the same
67
68
/// kind.
68
- #[ derive( Copy , Clone , PartialEq , Eq ) ]
69
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , TypeVisitable , TypeFoldable ) ]
69
70
enum PointerKind < ' tcx > {
70
71
/// No metadata attached, ie pointer to sized type or foreign type
71
72
Thin ,
@@ -74,11 +75,11 @@ enum PointerKind<'tcx> {
74
75
/// Slice
75
76
Length ,
76
77
/// The unsize info of this projection
77
- OfProjection ( & ' tcx ty:: ProjectionTy < ' tcx > ) ,
78
+ OfProjection ( ty:: ProjectionTy < ' tcx > ) ,
78
79
/// The unsize info of this opaque ty
79
80
OfOpaque ( DefId , SubstsRef < ' tcx > ) ,
80
81
/// The unsize info of this parameter
81
- OfParam ( & ' tcx ty:: ParamTy ) ,
82
+ OfParam ( ty:: ParamTy ) ,
82
83
}
83
84
84
85
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
@@ -119,9 +120,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
119
120
// Pointers to foreign types are thin, despite being unsized
120
121
ty:: Foreign ( ..) => Some ( PointerKind :: Thin ) ,
121
122
// We should really try to normalize here.
122
- ty:: Projection ( ref pi) => Some ( PointerKind :: OfProjection ( pi) ) ,
123
+ ty:: Projection ( pi) => Some ( PointerKind :: OfProjection ( pi) ) ,
123
124
ty:: Opaque ( def_id, substs) => Some ( PointerKind :: OfOpaque ( def_id, substs) ) ,
124
- ty:: Param ( ref p) => Some ( PointerKind :: OfParam ( p) ) ,
125
+ ty:: Param ( p) => Some ( PointerKind :: OfParam ( p) ) ,
125
126
// Insufficient type information.
126
127
ty:: Placeholder ( ..) | ty:: Bound ( ..) | ty:: Infer ( _) => None ,
127
128
@@ -903,7 +904,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
903
904
}
904
905
905
906
// vtable kinds must match
906
- if cast_kind == expr_kind {
907
+ if fcx . tcx . erase_regions ( cast_kind) == fcx . tcx . erase_regions ( expr_kind) {
907
908
Ok ( CastKind :: PtrPtrCast )
908
909
} else {
909
910
Err ( CastError :: DifferingKinds )
0 commit comments