about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2016-03-13 20:03:48 +0200
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2016-06-08 23:58:53 +0300
commit088b7e2108abd54a31d573301d7c90e012d09150 (patch)
treeda0d9328f2e5e669fdef8fe3dfb59465f2485e10
parent70c25c848c3dc0f75675622e59d6dca47de84b0b (diff)
fix translation of unsized types and arrays
-rw-r--r--src/librustc_trans/_match.rs16
-rw-r--r--src/test/run-pass/match-unsized.rs18
2 files changed, 32 insertions, 2 deletions
diff --git a/src/librustc_trans/_match.rs b/src/librustc_trans/_match.rs
index 74e8daf97e3..bdfe014051c 100644
--- a/src/librustc_trans/_match.rs
+++ b/src/librustc_trans/_match.rs
@@ -729,7 +729,14 @@ fn bind_subslice_pat(bcx: Block,
     let (base, len) = vec_datum.get_vec_base_and_len(bcx);
 
     let slice_begin = InBoundsGEP(bcx, base, &[C_uint(bcx.ccx(), offset_left)]);
-    let slice_len_offset = C_uint(bcx.ccx(), offset_left + offset_right);
+    let diff = offset_left + offset_right;
+    if let ty::TyArray(ty, n) = vec_ty_contents.sty {
+        let array_ty = bcx.tcx().mk_array(ty, n-diff);
+        let llty_array = type_of::type_of(bcx.ccx(), array_ty);
+        return PointerCast(bcx, slice_begin, llty_array.ptr_to());
+    }
+
+    let slice_len_offset = C_uint(bcx.ccx(), diff);
     let slice_len = Sub(bcx, len, slice_len_offset, DebugLoc::None);
     let slice_ty = bcx.tcx().mk_imm_ref(bcx.tcx().mk_region(ty::ReErased),
                                          bcx.tcx().mk_slice(unit_ty));
@@ -1205,7 +1212,12 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
         }
         Some(field_vals)
     } else if any_uniq_pat(m, col) || any_region_pat(m, col) {
-        Some(vec!(Load(bcx, val.val)))
+        let ptr = if type_is_fat_ptr(bcx.tcx(), left_ty) {
+            val.val
+        } else {
+            Load(bcx, val.val)
+        };
+        Some(vec!(ptr))
     } else {
         match left_ty.sty {
             ty::TyArray(_, n) => {
diff --git a/src/test/run-pass/match-unsized.rs b/src/test/run-pass/match-unsized.rs
new file mode 100644
index 00000000000..7253672a7ff
--- /dev/null
+++ b/src/test/run-pass/match-unsized.rs
@@ -0,0 +1,18 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    let data: &'static str = "Hello, World!";
+    match data {
+        &ref xs => {
+            assert_eq!(data, xs);
+        }
+    }
+}