Skip to content

Commit c1bfd0c

Browse files
committed
implement lvalue_len
no tests - sorry
1 parent dcb64b5 commit c1bfd0c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/librustc_trans/trans/mir/lvalue.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use llvm::ValueRef;
12-
use rustc::middle::ty::Ty;
12+
use rustc::middle::ty::{self, Ty};
1313
use rustc_mir::repr as mir;
1414
use rustc_mir::tcx::LvalueTy;
1515
use trans::adt;
@@ -52,10 +52,17 @@ impl<'tcx> LvalueRef<'tcx> {
5252

5353
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
5454
pub fn lvalue_len(&mut self,
55-
_bcx: Block<'bcx, 'tcx>,
56-
_lvalue: LvalueRef<'tcx>)
55+
bcx: Block<'bcx, 'tcx>,
56+
lvalue: LvalueRef<'tcx>)
5757
-> ValueRef {
58-
unimplemented!()
58+
match lvalue.ty.to_ty(bcx.tcx()).sty {
59+
ty::TyArray(_, n) => common::C_uint(bcx.ccx(), n),
60+
ty::TySlice(_) | ty::TyStr => {
61+
assert!(lvalue.llextra != ptr::null_mut());
62+
lvalue.llextra
63+
}
64+
_ => bcx.sess().bug("unexpected type in get_base_and_len"),
65+
}
5966
}
6067

6168
pub fn trans_lvalue(&mut self,

0 commit comments

Comments
 (0)