]> git.lizzy.rs Git - rust.git/commitdiff
Fix trans_ptr_binop for fn()
authorbjorn3 <bjorn3@users.noreply.github.com>
Sun, 15 Sep 2019 16:15:40 +0000 (18:15 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 15 Sep 2019 16:35:56 +0000 (18:35 +0200)
src/num.rs

index 442ff48550c7117be36375c8e0c401ce01cf677f..49df9b3ac9c5e73c36e642ba1b2155a2aef14e17 100644 (file)
@@ -347,9 +347,11 @@ pub fn trans_ptr_binop<'tcx>(
     in_lhs: CValue<'tcx>,
     in_rhs: CValue<'tcx>,
 ) -> CValue<'tcx> {
-    let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
+    let is_thin_ptr = in_lhs.layout().ty.builtin_deref(true).map(|TypeAndMut { ty, mutbl: _}| {
+        !has_ptr_meta(fx.tcx, ty)
+    }).unwrap_or(true);
 
-    if !has_ptr_meta(fx.tcx, pointee_ty) {
+    if is_thin_ptr {
         match bin_op {
             BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
                 let lhs = in_lhs.load_scalar(fx);
@@ -358,6 +360,7 @@ pub fn trans_ptr_binop<'tcx>(
                 return codegen_compare_bin_op(fx, bin_op, false, lhs, rhs);
             }
             BinOp::Offset => {
+                let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
                 let (base, offset) = (in_lhs, in_rhs.load_scalar(fx));
                 let pointee_size = fx.layout_of(pointee_ty).size.bytes();
                 let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);