@@ -125,35 +125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
125125 self . check_expr_with_expectation ( e, expected)
126126 }
127127 ExprKind :: Array ( ref args) => {
128- let uty = expected. to_option ( self ) . and_then ( |uty| {
129- match uty. sty {
130- ty:: Array ( ty, _) | ty:: Slice ( ty) => Some ( ty) ,
131- _ => None
132- }
133- } ) ;
134-
135- let element_ty = if !args. is_empty ( ) {
136- let coerce_to = uty. unwrap_or_else ( || {
137- self . next_ty_var ( TypeVariableOrigin {
138- kind : TypeVariableOriginKind :: TypeInference ,
139- span : expr. span ,
140- } )
141- } ) ;
142- let mut coerce = CoerceMany :: with_coercion_sites ( coerce_to, args) ;
143- assert_eq ! ( self . diverges. get( ) , Diverges :: Maybe ) ;
144- for e in args {
145- let e_ty = self . check_expr_with_hint ( e, coerce_to) ;
146- let cause = self . misc ( e. span ) ;
147- coerce. coerce ( self , & cause, e, e_ty) ;
148- }
149- coerce. complete ( self )
150- } else {
151- self . next_ty_var ( TypeVariableOrigin {
152- kind : TypeVariableOriginKind :: TypeInference ,
153- span : expr. span ,
154- } )
155- } ;
156- tcx. mk_array ( element_ty, args. len ( ) as u64 )
128+ self . check_expr_array ( args, expected, expr)
157129 }
158130 ExprKind :: Repeat ( ref element, ref count) => {
159131 let count_def_id = tcx. hir ( ) . local_def_id_from_hir_id ( count. hir_id ) ;
@@ -815,4 +787,41 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
815787 }
816788 }
817789 }
790+
791+ fn check_expr_array (
792+ & self ,
793+ args : & ' tcx [ hir:: Expr ] ,
794+ expected : Expectation < ' tcx > ,
795+ expr : & ' tcx hir:: Expr
796+ ) -> Ty < ' tcx > {
797+ let uty = expected. to_option ( self ) . and_then ( |uty| {
798+ match uty. sty {
799+ ty:: Array ( ty, _) | ty:: Slice ( ty) => Some ( ty) ,
800+ _ => None
801+ }
802+ } ) ;
803+
804+ let element_ty = if !args. is_empty ( ) {
805+ let coerce_to = uty. unwrap_or_else ( || {
806+ self . next_ty_var ( TypeVariableOrigin {
807+ kind : TypeVariableOriginKind :: TypeInference ,
808+ span : expr. span ,
809+ } )
810+ } ) ;
811+ let mut coerce = CoerceMany :: with_coercion_sites ( coerce_to, args) ;
812+ assert_eq ! ( self . diverges. get( ) , Diverges :: Maybe ) ;
813+ for e in args {
814+ let e_ty = self . check_expr_with_hint ( e, coerce_to) ;
815+ let cause = self . misc ( e. span ) ;
816+ coerce. coerce ( self , & cause, e, e_ty) ;
817+ }
818+ coerce. complete ( self )
819+ } else {
820+ self . next_ty_var ( TypeVariableOrigin {
821+ kind : TypeVariableOriginKind :: TypeInference ,
822+ span : expr. span ,
823+ } )
824+ } ;
825+ self . tcx . mk_array ( element_ty, args. len ( ) as u64 )
826+ }
818827}
0 commit comments