Skip to content

Commit 088b7e2

Browse files
committed
fix translation of unsized types and arrays
1 parent 70c25c8 commit 088b7e2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/librustc_trans/_match.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,14 @@ fn bind_subslice_pat(bcx: Block,
729729
let (base, len) = vec_datum.get_vec_base_and_len(bcx);
730730

731731
let slice_begin = InBoundsGEP(bcx, base, &[C_uint(bcx.ccx(), offset_left)]);
732-
let slice_len_offset = C_uint(bcx.ccx(), offset_left + offset_right);
732+
let diff = offset_left + offset_right;
733+
if let ty::TyArray(ty, n) = vec_ty_contents.sty {
734+
let array_ty = bcx.tcx().mk_array(ty, n-diff);
735+
let llty_array = type_of::type_of(bcx.ccx(), array_ty);
736+
return PointerCast(bcx, slice_begin, llty_array.ptr_to());
737+
}
738+
739+
let slice_len_offset = C_uint(bcx.ccx(), diff);
733740
let slice_len = Sub(bcx, len, slice_len_offset, DebugLoc::None);
734741
let slice_ty = bcx.tcx().mk_imm_ref(bcx.tcx().mk_region(ty::ReErased),
735742
bcx.tcx().mk_slice(unit_ty));
@@ -1205,7 +1212,12 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
12051212
}
12061213
Some(field_vals)
12071214
} else if any_uniq_pat(m, col) || any_region_pat(m, col) {
1208-
Some(vec!(Load(bcx, val.val)))
1215+
let ptr = if type_is_fat_ptr(bcx.tcx(), left_ty) {
1216+
val.val
1217+
} else {
1218+
Load(bcx, val.val)
1219+
};
1220+
Some(vec!(ptr))
12091221
} else {
12101222
match left_ty.sty {
12111223
ty::TyArray(_, n) => {

src/test/run-pass/match-unsized.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let data: &'static str = "Hello, World!";
13+
match data {
14+
&ref xs => {
15+
assert_eq!(data, xs);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)