@@ -310,26 +310,23 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
310310 return expr:: trans_into ( bcx, & * * element, Ignore ) ;
311311 }
312312 SaveIn ( lldest) => {
313- let count = ty:: eval_repeat_count ( bcx. tcx ( ) , & * * count_expr) ;
314- if count == 0 {
315- return bcx;
313+ match ty:: eval_repeat_count ( bcx. tcx ( ) , & * * count_expr) {
314+ 0 => bcx,
315+ 1 => expr:: trans_into ( bcx, & * * element, SaveIn ( lldest) ) ,
316+ count => {
317+ let elem = unpack_datum ! ( bcx, expr:: trans( bcx, & * * element) ) ;
318+ assert ! ( !ty:: type_moves_by_default( bcx. tcx( ) , elem. ty) ) ;
319+
320+ let bcx = iter_vec_loop ( bcx, lldest, vt,
321+ C_uint ( bcx. ccx ( ) , count) ,
322+ |set_bcx, lleltptr, _| {
323+ elem. shallow_copy ( set_bcx, lleltptr)
324+ } ) ;
325+
326+ elem. add_clean_if_rvalue ( bcx, element. id ) ;
327+ bcx
328+ }
316329 }
317-
318- // Some cleanup would be required in the case in which panic happens
319- // during a copy. But given that copy constructors are not overridable,
320- // this can only happen as a result of OOM. So we just skip out on the
321- // cleanup since things would *probably* be broken at that point anyways.
322-
323- let elem = unpack_datum ! ( bcx, expr:: trans( bcx, & * * element) ) ;
324- assert ! ( !ty:: type_moves_by_default( bcx. tcx( ) , elem. ty) ) ;
325-
326- let bcx = iter_vec_loop ( bcx, lldest, vt,
327- C_uint ( bcx. ccx ( ) , count) , |set_bcx, lleltptr, _| {
328- elem. shallow_copy ( set_bcx, lleltptr)
329- } ) ;
330-
331- elem. add_clean_if_rvalue ( bcx, element. id ) ;
332- bcx
333330 }
334331 }
335332 }
0 commit comments