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