Skip to content

Commit 7ec6f7b

Browse files
committed
Fix the named tuple constructor code to return a value
This is essentially the same change as in `intrinsics`. Returns a value or `()` depending on whether or not the type is immediate.
1 parent 79d69a7 commit 7ec6f7b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,8 +1672,7 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
16721672
disr: ty::Disr,
16731673
args: callee::CallArgs,
16741674
dest: expr::Dest,
1675-
debug_loc: DebugLoc)
1676-
-> Result<'blk, 'tcx> {
1675+
debug_loc: DebugLoc) -> Result<'blk, 'tcx> {
16771676

16781677
let ccx = bcx.fcx.ccx;
16791678
let tcx = ccx.tcx();
@@ -1717,6 +1716,12 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
17171716
}
17181717
}
17191718

1719+
let val = if type_is_immediate(ccx, result_ty) && !type_is_zero_size(ccx, result_ty) {
1720+
load_ty(bcx, llresult, result_ty)
1721+
} else {
1722+
common::C_nil(ccx)
1723+
};
1724+
17201725
// If the caller doesn't care about the result
17211726
// drop the temporary we made
17221727
let bcx = match dest {
@@ -1730,7 +1735,7 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
17301735
}
17311736
};
17321737

1733-
Result::new(bcx, llresult)
1738+
Result::new(bcx, val)
17341739
}
17351740

17361741
pub fn trans_tuple_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,

src/librustc_trans/trans/expr.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
585585
if let ast::ExprPath(..) = f.node {
586586
let fn_ty = expr_ty_adjusted(bcx, f);
587587
let (fty, ret_ty) = match fn_ty.sty {
588-
ty::ty_bare_fn(_, ref fty) => {
588+
ty::TyBareFn(_, ref fty) => {
589589
(fty, ty::erase_late_bound_regions(bcx.tcx(), &fty.sig.output()))
590590
}
591591
_ => panic!("Not calling a function?!")
@@ -595,12 +595,9 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
595595
let is_rust_fn = fty.abi == synabi::Rust ||
596596
fty.abi == synabi::RustIntrinsic;
597597

598-
let valid_type =
599-
ty::type_is_scalar(ret_ty) ||
600-
ty::type_is_simd(bcx.tcx(), ret_ty);
601-
602-
if is_rust_fn && type_is_immediate(bcx.ccx(), ret_ty) && valid_type {
598+
let needs_drop = type_needs_drop(bcx.tcx(), ret_ty);
603599

600+
if is_rust_fn && type_is_immediate(bcx.ccx(), ret_ty) && !needs_drop {
604601
let args = callee::ArgExprs(&args[..]);
605602
let result = callee::trans_call_inner(bcx,
606603
expr.debug_loc(),

0 commit comments

Comments
 (0)