From c1bfd0ca6b6aedd4fa29e3dddf927f31051f3ea6 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Tue, 10 Nov 2015 22:26:59 +0200 Subject: [PATCH] implement lvalue_len no tests - sorry --- src/librustc_trans/trans/mir/lvalue.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/librustc_trans/trans/mir/lvalue.rs b/src/librustc_trans/trans/mir/lvalue.rs index d846307dc78..f6aa79393d3 100644 --- a/src/librustc_trans/trans/mir/lvalue.rs +++ b/src/librustc_trans/trans/mir/lvalue.rs @@ -9,7 +9,7 @@ // except according to those terms. use llvm::ValueRef; -use rustc::middle::ty::Ty; +use rustc::middle::ty::{self, Ty}; use rustc_mir::repr as mir; use rustc_mir::tcx::LvalueTy; use trans::adt; @@ -52,10 +52,17 @@ pub fn alloca<'bcx>(bcx: Block<'bcx, 'tcx>, impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { pub fn lvalue_len(&mut self, - _bcx: Block<'bcx, 'tcx>, - _lvalue: LvalueRef<'tcx>) + bcx: Block<'bcx, 'tcx>, + lvalue: LvalueRef<'tcx>) -> ValueRef { - unimplemented!() + match lvalue.ty.to_ty(bcx.tcx()).sty { + ty::TyArray(_, n) => common::C_uint(bcx.ccx(), n), + ty::TySlice(_) | ty::TyStr => { + assert!(lvalue.llextra != ptr::null_mut()); + lvalue.llextra + } + _ => bcx.sess().bug("unexpected type in get_base_and_len"), + } } pub fn trans_lvalue(&mut self, -- GitLab