@@ -33,6 +33,7 @@ use super::FnCtxt;
3333use crate :: type_error_struct;
3434use rustc_errors:: { struct_span_err, Applicability , DelayDm , DiagnosticBuilder , ErrorGuaranteed } ;
3535use rustc_hir as hir;
36+ use rustc_macros:: { TypeFoldable , TypeVisitable } ;
3637use rustc_middle:: mir:: Mutability ;
3738use rustc_middle:: ty:: adjustment:: AllowTwoPhase ;
3839use rustc_middle:: ty:: cast:: { CastKind , CastTy } ;
@@ -65,7 +66,7 @@ pub struct CastCheck<'tcx> {
6566/// The kind of pointer and associated metadata (thin, length or vtable) - we
6667/// only allow casts between fat pointers if their metadata have the same
6768/// kind.
68- #[ derive( Copy , Clone , PartialEq , Eq ) ]
69+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , TypeVisitable , TypeFoldable ) ]
6970enum PointerKind < ' tcx > {
7071 /// No metadata attached, ie pointer to sized type or foreign type
7172 Thin ,
@@ -74,11 +75,11 @@ enum PointerKind<'tcx> {
7475 /// Slice
7576 Length ,
7677 /// The unsize info of this projection
77- OfProjection ( & ' tcx ty:: ProjectionTy < ' tcx > ) ,
78+ OfProjection ( ty:: ProjectionTy < ' tcx > ) ,
7879 /// The unsize info of this opaque ty
7980 OfOpaque ( DefId , SubstsRef < ' tcx > ) ,
8081 /// The unsize info of this parameter
81- OfParam ( & ' tcx ty:: ParamTy ) ,
82+ OfParam ( ty:: ParamTy ) ,
8283}
8384
8485impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
@@ -119,9 +120,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
119120 // Pointers to foreign types are thin, despite being unsized
120121 ty:: Foreign ( ..) => Some ( PointerKind :: Thin ) ,
121122 // We should really try to normalize here.
122- ty:: Projection ( ref pi) => Some ( PointerKind :: OfProjection ( pi) ) ,
123+ ty:: Projection ( pi) => Some ( PointerKind :: OfProjection ( pi) ) ,
123124 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) ) ,
125126 // Insufficient type information.
126127 ty:: Placeholder ( ..) | ty:: Bound ( ..) | ty:: Infer ( _) => None ,
127128
@@ -903,7 +904,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
903904 }
904905
905906 // vtable kinds must match
906- if cast_kind == expr_kind {
907+ if fcx . tcx . erase_regions ( cast_kind) == fcx . tcx . erase_regions ( expr_kind) {
907908 Ok ( CastKind :: PtrPtrCast )
908909 } else {
909910 Err ( CastError :: DifferingKinds )
0 commit comments