@@ -1051,20 +1051,19 @@ impl<'a, 'tcx> CastCheck<'tcx> {
1051
1051
fn check_ref_cast (
1052
1052
& self ,
1053
1053
fcx : & FnCtxt < ' a , ' tcx > ,
1054
- m_expr : ty:: TypeAndMut < ' tcx > ,
1055
- m_cast : ty:: TypeAndMut < ' tcx > ,
1054
+ mut m_expr : ty:: TypeAndMut < ' tcx > ,
1055
+ mut m_cast : ty:: TypeAndMut < ' tcx > ,
1056
1056
) -> Result < CastKind , CastError < ' tcx > > {
1057
1057
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
1058
+ m_expr. ty = fcx. try_structurally_resolve_type ( self . expr_span , m_expr. ty ) ;
1059
+ m_cast. ty = fcx. try_structurally_resolve_type ( self . cast_span , m_cast. ty ) ;
1060
+
1058
1061
if m_expr. mutbl >= m_cast. mutbl
1059
1062
&& let ty:: Array ( ety, _) = m_expr. ty . kind ( )
1060
1063
&& fcx. can_eq ( fcx. param_env , * ety, m_cast. ty )
1061
1064
{
1062
- // Due to the limitations of LLVM global constants,
1063
- // region pointers end up pointing at copies of
1064
- // vector elements instead of the original values.
1065
- // To allow raw pointers to work correctly, we
1066
- // need to special-case obtaining a raw pointer
1067
- // from a region pointer to a vector.
1065
+ // Due to historical reasons we allow directly casting references of
1066
+ // arrays into raw pointers of their element type.
1068
1067
1069
1068
// Coerce to a raw pointer so that we generate RawPtr in MIR.
1070
1069
let array_ptr_type = Ty :: new_ptr ( fcx. tcx , m_expr. ty , m_expr. mutbl ) ;
0 commit comments