]> git.lizzy.rs Git - rust.git/commitdiff
Implement casting between TyRef and TyRawPtr
authorbjorn3 <bjorn3@users.noreply.github.com>
Wed, 18 Jul 2018 12:21:13 +0000 (14:21 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Wed, 18 Jul 2018 12:21:13 +0000 (14:21 +0200)
example.rs
src/base.rs

index 7dc816aa7dc9118e16524570acda523addf6cc6b..d7ef02244507770cb0825d82dfbfd35357649a99 100644 (file)
@@ -85,3 +85,7 @@ fn return_str() -> &'static str {
 fn promoted_val() -> &'static u8 {
     &(1 * 2)
 }
+
+fn cast_ref_to_raw_ptr(abc: &u8) -> *const u8 {
+    abc as *const u8
+}
index 31eb6e462bfd9fded5d592a93b3bf6801251af69..c17e9d02409373ae6e365dde00b7fea591de0985 100644 (file)
@@ -371,7 +371,19 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
                     let layout = fx.layout_of(ty);
                     lval.write_cvalue(fx, operand.unchecked_cast_to(layout));
                 }
-                Rvalue::Cast(CastKind::Misc, operand, ty) => unimplemented!("rval misc {:?} {:?}", operand, ty),
+                Rvalue::Cast(CastKind::Misc, operand, ty) => {
+                    let operand = trans_operand(fx, operand);
+                    match (&operand.layout().ty.sty, &ty.sty) {
+                        (TypeVariants::TyRef(..), TypeVariants::TyRef(..)) |
+                        (TypeVariants::TyRef(..), TypeVariants::TyRawPtr(..)) |
+                        (TypeVariants::TyRawPtr(..), TypeVariants::TyRef(..)) |
+                        (TypeVariants::TyRawPtr(..), TypeVariants::TyRawPtr(..)) => {
+                            let layout = fx.layout_of(ty);
+                            lval.write_cvalue(fx, operand.unchecked_cast_to(layout));
+                        }
+                        _ => unimplemented!("rval misc {:?} {:?}", operand, ty),
+                    }
+                },
                 Rvalue::Cast(CastKind::ClosureFnPointer, operand, ty) => unimplemented!("rval closure_fn_ptr {:?} {:?}", operand, ty),
                 Rvalue::Cast(CastKind::Unsize, operand, ty) => unimplemented!("rval unsize {:?} {:?}", operand, ty),
                 Rvalue::Discriminant(place) => {
@@ -436,7 +448,7 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
                     }
                 }
                 Rvalue::Repeat(operand, times) => unimplemented!("rval repeat {:?} {:?}", operand, times),
-                Rvalue::Len(lval) => unimplemented!("rval len {:?}", lval),
+                Rvalue::Len(lval) => return Err(format!("rval len {:?}", lval)),
                 Rvalue::NullaryOp(NullOp::Box, ty) => unimplemented!("rval box {:?}", ty),
                 Rvalue::NullaryOp(NullOp::SizeOf, ty) => unimplemented!("rval size_of {:?}", ty),
                 Rvalue::Aggregate(_, _) => bug!("shouldn't exist at trans {:?}", rval),