/// &[...] allocates memory on the stack and writes the values into it, returning the vector (the
/// caller must make the reference).  "..." is similar except that the memory can be statically
/// allocated and we return a reference (strings are always by-ref).
&[...] allocates memory on the stack and writes the values into it, returning the vector (the
caller must make the reference).  "..." is similar except that the memory can be statically
allocated and we return a reference (strings are always by-ref).
& [ ... ] allocates memory on the stack and writes the values into it returning the vector ( the caller must make the reference ) . " ... " is similar except that the memory can be statically allocated and we return a reference ( strings are always by - ref ) .
pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                   slice_expr: &hir::Expr,
                                   content_expr: &hir::Expr)
                                   -> DatumBlock<'blk, 'tcx, Expr> {
    let fcx = bcx.fcx;
    let ccx = fcx.ccx;
    let mut bcx = bcx;
    debug!("trans_slice_vec(slice_expr={:?})",
           slice_expr);
    let vec_ty = node_id_type(bcx, slice_expr.id);
    // Handle the "..." case (returns a slice since strings are always unsized):
    if let hir::ExprLit(ref lit) = content_expr.node {
        if let hir::LitStr(ref s, _) = lit.node {
            let scratch = rvalue_scratch_datum(bcx, vec_ty, "");
            bcx = trans_lit_str(bcx,
                                content_expr,
                                s.clone(),
                                SaveIn(scratch.val));
            return DatumBlock::new(bcx, scratch.to_expr_datum());
        }
    }
    // Handle the &[...] case:
    let vt = vec_types_from_expr(bcx, content_expr);
    let count = elements_required(bcx, content_expr);
    debug!("    vt={}, count={}", vt.to_string(ccx), count);
    let fixed_ty = bcx.tcx().mk_array(vt.unit_ty, count);
    // Always create an alloca even if zero-sized, to preserve
    // the non-null invariant of the inner slice ptr
    let llfixed = base::alloc_ty(bcx, fixed_ty, "");
    call_lifetime_start(bcx, llfixed);
    if count > 0 {
        // Arrange for the backing array to be cleaned up.
        let cleanup_scope = cleanup::temporary_scope(bcx.tcx(), content_expr.id);
        fcx.schedule_lifetime_end(cleanup_scope, llfixed);
        fcx.schedule_drop_mem(cleanup_scope, llfixed, fixed_ty, None);
        // Generate the content into the backing array.
        // llfixed has type *[T x N], but we want the type *T,
        // so use GEP to convert
        bcx = write_content(bcx, &vt, slice_expr, content_expr,
                            SaveIn(StructGEP(bcx, llfixed, 0)));
    };
    immediate_rvalue_bcx(bcx, llfixed, vec_ty).to_expr_datumblock()
}
pub fn trans_slice_vec < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , slice_expr : & hir :: Expr , content_expr : & hir :: Expr ) -> DatumBlock < ' blk , ' tcx , Expr > { let fcx = bcx . fcx ; let ccx = fcx . ccx ; let mut bcx = bcx ; debug ! ( " " slice_expr ) ; let vec_ty = node_id_type ( bcx , slice_expr . id ) ; // Handle the "..." case (returns a slice since strings are always unsized): if let hir :: ExprLit ( ref lit ) = content_expr . node { if let hir :: LitStr ( ref s , _ ) = lit . node { let scratch = rvalue_scratch_datum ( bcx , vec_ty , " " ) ; bcx = trans_lit_str ( bcx , content_expr , s . clone ( ) , SaveIn ( scratch . val ) ) ; return DatumBlock :: new ( bcx , scratch . to_expr_datum ( ) ) ; } } // Handle the &[...] case: let vt = vec_types_from_expr ( bcx , content_expr ) ; let count = elements_required ( bcx , content_expr ) ; debug ! ( " " vt to_string ( ccx ) count ) ; let fixed_ty = bcx . tcx ( ) . mk_array ( vt . unit_ty , count ) ; // Always create an alloca even if zero-sized, to preserve // the non-null invariant of the inner slice ptr let llfixed = base :: alloc_ty ( bcx , fixed_ty , " " ) ; call_lifetime_start ( bcx , llfixed ) ; if count > 0 { // Arrange for the backing array to be cleaned up. let cleanup_scope = cleanup :: temporary_scope ( bcx . tcx ( ) , content_expr . id ) ; fcx . schedule_lifetime_end ( cleanup_scope , llfixed ) ; fcx . schedule_drop_mem ( cleanup_scope , llfixed , fixed_ty , None ) ; // Generate the content into the backing array. // llfixed has type *[T x N], but we want the type *T, // so use GEP to convert bcx = write_content ( bcx , & vt , slice_expr , content_expr , SaveIn ( StructGEP ( bcx , llfixed , 0 ) ) ) ; } ; immediate_rvalue_bcx ( bcx , llfixed , vec_ty ) . to_expr_datumblock ( ) }
&[...] allocates memory on the stack and writes the values into it, returning the vector (the
caller must make the reference).
& [ ... ] allocates memory on the stack and writes the values into it returning the vector ( the caller must make the reference ) .
bcx
Block<'blk, 'tcx>
slice_expr
&hir::Expr
content_expr
&hir::Expr