@@ -3752,36 +3752,27 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3752
3752
typ
3753
3753
}
3754
3754
hir:: ExprArray ( ref args) => {
3755
- let uty = expected. to_option ( self ) . and_then ( |uty| {
3756
- match uty. sty {
3757
- ty:: TyArray ( ty, _) | ty:: TySlice ( ty) => Some ( ty) ,
3758
- _ => None
3759
- }
3760
- } ) ;
3761
-
3762
- let mut unified = self . next_ty_var ( TypeVariableOrigin :: TypeInference ( expr. span ) ) ;
3763
- let coerce_to = uty. unwrap_or ( unified) ;
3764
-
3765
- for ( i, e) in args. iter ( ) . enumerate ( ) {
3766
- let e_ty = self . check_expr_with_hint ( e, coerce_to) ;
3767
- let cause = self . misc ( e. span ) ;
3768
-
3769
- // Special-case the first element, as it has no "previous expressions".
3770
- let result = if i == 0 {
3771
- self . try_coerce ( e, e_ty, coerce_to)
3772
- } else {
3773
- let prev_elems = || args[ ..i] . iter ( ) . map ( |e| & * e) ;
3774
- self . try_find_coercion_lub ( & cause, prev_elems, unified, e, e_ty)
3775
- } ;
3755
+ let uty = expected. to_option ( self ) . and_then ( |uty| {
3756
+ match uty. sty {
3757
+ ty:: TyArray ( ty, _) | ty:: TySlice ( ty) => Some ( ty) ,
3758
+ _ => None
3759
+ }
3760
+ } ) ;
3776
3761
3777
- match result {
3778
- Ok ( ty) => unified = ty,
3779
- Err ( e) => {
3780
- self . report_mismatched_types ( & cause, unified, e_ty, e) . emit ( ) ;
3781
- }
3782
- }
3783
- }
3784
- tcx. mk_array ( unified, args. len ( ) )
3762
+ let element_ty = if !args. is_empty ( ) {
3763
+ let coerce_to = uty. unwrap_or_else (
3764
+ || self . next_ty_var ( TypeVariableOrigin :: TypeInference ( expr. span ) ) ) ;
3765
+ let mut coerce = CoerceMany :: new ( coerce_to) ;
3766
+ for e in args {
3767
+ let e_ty = self . check_expr_with_hint ( e, coerce_to) ;
3768
+ let cause = self . misc ( e. span ) ;
3769
+ coerce. coerce ( self , & cause, e, e_ty) ;
3770
+ }
3771
+ coerce. complete ( self )
3772
+ } else {
3773
+ self . next_ty_var ( TypeVariableOrigin :: TypeInference ( expr. span ) )
3774
+ } ;
3775
+ tcx. mk_array ( element_ty, args. len ( ) )
3785
3776
}
3786
3777
hir:: ExprRepeat ( ref element, count) => {
3787
3778
let count = eval_length ( self . tcx . global_tcx ( ) , count, "repeat count" )
0 commit comments