File tree 1 file changed +15
-1
lines changed
compiler/rustc_hir_typeck/src
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -1062,8 +1062,22 @@ impl<'a, 'tcx> CastCheck<'tcx> {
1062
1062
)
1063
1063
} ) ;
1064
1064
1065
+ let erased_ety = fcx. tcx . erase_regions ( * ety) ;
1066
+ let erased_m_cast = fcx. tcx . erase_regions ( m_cast. ty ) ;
1067
+
1068
+ let expected = if matches ! ( m_cast. ty. kind( ) , ty:: Array ( _, _) )
1069
+ && !erased_ety. eq ( & erased_m_cast)
1070
+ {
1071
+ // if the expected type is [ty1; N] and the actual type is [ty2; M], and ty is not [ty2; M]
1072
+ // then we need to use [ty1; N] as the expected type
1073
+ m_expr. ty
1074
+ } else {
1075
+ // otherwise, use the expected type as the expected type
1076
+ * ety
1077
+ } ;
1078
+
1065
1079
// this will report a type mismatch if needed
1066
- fcx. demand_eqtype ( self . span , * ety , m_cast. ty ) ;
1080
+ fcx. demand_eqtype ( self . span , expected , m_cast. ty ) ;
1067
1081
return Ok ( CastKind :: ArrayPtrCast ) ;
1068
1082
}
1069
1083
}
You can’t perform that action at this time.
0 commit comments