Skip to content

Commit 7f777a5

Browse files
committed
auto merge of #14752 : jakub-/rust/issue-11940, r=alexcrichton
Fixes #8315 Fixes #11940
2 parents 9bb8f88 + f8b4e82 commit 7f777a5

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

Diff for: src/librustc/middle/trans/_match.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,12 @@ fn trans_opt<'a>(bcx: &'a Block<'a>, o: &Opt) -> opt_result<'a> {
312312
let datum = datum::rvalue_scratch_datum(bcx, struct_ty, "");
313313
return single_result(Result::new(bcx, datum.val));
314314
}
315-
lit(ConstLit(lit_id)) => {
316-
let (llval, _) = consts::get_const_val(bcx.ccx(), lit_id);
317-
return single_result(Result::new(bcx, llval));
315+
lit(l @ ConstLit(ref def_id)) => {
316+
let lit_ty = ty::node_id_to_type(bcx.tcx(), lit_to_expr(bcx.tcx(), &l).id);
317+
let (llval, _) = consts::get_const_val(bcx.ccx(), *def_id);
318+
let lit_datum = immediate_rvalue(llval, lit_ty);
319+
let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx));
320+
return single_result(Result::new(bcx, lit_datum.val));
318321
}
319322
var(disr_val, ref repr) => {
320323
return adt::trans_case(bcx, &**repr, disr_val);

Diff for: src/librustc/middle/trans/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
599599
let len = s.get().len();
600600
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s, false),
601601
Type::i8p(cx).to_ref());
602-
C_struct(cx, [cs, C_uint(cx, len)], false)
602+
C_named_struct(cx.tn.find_type("str_slice").unwrap(), [cs, C_uint(cx, len)])
603603
}
604604
}
605605

Diff for: src/librustc/middle/trans/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ impl CrateContext {
233233
ccx.int_type = Type::int(&ccx);
234234
ccx.opaque_vec_type = Type::opaque_vec(&ccx);
235235

236-
ccx.tn.associate_type("tydesc", &Type::tydesc(&ccx));
237-
238236
let mut str_slice_ty = Type::named_struct(&ccx, "str_slice");
239237
str_slice_ty.set_struct_body([Type::i8p(&ccx), ccx.int_type], false);
240238
ccx.tn.associate_type("str_slice", &str_slice_ty);
241239

240+
ccx.tn.associate_type("tydesc", &Type::tydesc(&ccx, str_slice_ty));
241+
242242
if ccx.sess().count_llvm_insns() {
243243
base::init_insn_ctxt()
244244
}

Diff for: src/librustc/middle/trans/controlflow.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::trans::cleanup;
2020
use middle::trans::common::*;
2121
use middle::trans::debuginfo;
2222
use middle::trans::expr;
23-
use middle::trans::type_of;
2423
use middle::ty;
2524
use util::ppaux::Repr;
2625

@@ -343,14 +342,10 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>,
343342

344343
fn str_slice_arg<'a>(bcx: &'a Block<'a>, s: InternedString) -> ValueRef {
345344
let ccx = bcx.ccx();
346-
let t = ty::mk_str_slice(bcx.tcx(), ty::ReStatic, ast::MutImmutable);
347345
let s = C_str_slice(ccx, s);
348346
let slot = alloca(bcx, val_ty(s), "__temp");
349347
Store(bcx, s, slot);
350-
351-
// The type of C_str_slice is { i8*, i64 }, but the type of the &str is
352-
// %str_slice, so we do a bitcast here to the right type.
353-
BitCast(bcx, slot, type_of::type_of(ccx, t).ptr_to())
348+
slot
354349
}
355350

356351
pub fn trans_fail<'a>(

Diff for: src/librustc/middle/trans/type_.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Type {
186186
Type::func([t], &Type::void(ccx))
187187
}
188188

189-
pub fn tydesc(ccx: &CrateContext) -> Type {
189+
pub fn tydesc(ccx: &CrateContext, str_slice_ty: Type) -> Type {
190190
let mut tydesc = Type::named_struct(ccx, "tydesc");
191191
let glue_fn_ty = Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to();
192192

@@ -200,7 +200,7 @@ impl Type {
200200
int_ty, // align
201201
glue_fn_ty, // drop
202202
glue_fn_ty, // visit
203-
Type::struct_(ccx, [Type::i8p(ccx), Type::int(ccx)], false)]; // name
203+
str_slice_ty]; // name
204204
tydesc.set_struct_body(elems, false);
205205

206206
tydesc

Diff for: src/test/run-pass/issue-11940.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 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+
static TEST_STR: &'static str = "abcd";
12+
13+
fn main() {
14+
let s = "abcd";
15+
match s {
16+
TEST_STR => (),
17+
_ => unreachable!()
18+
}
19+
}

0 commit comments

Comments
 (0)