From 109e1184aa47cad4f866811fc547d7237e73194a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Sun, 15 Feb 2015 13:41:05 +0100 Subject: [PATCH] Apply adjustments to the retslot type in trans_ret Without the adjustments the retslot might have the wrong type, e.g. when the return value is implicitly coerced to a trait object. Fixes #22346 --- src/librustc_trans/trans/controlflow.rs | 2 +- src/test/run-pass/issue22346.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/issue22346.rs diff --git a/src/librustc_trans/trans/controlflow.rs b/src/librustc_trans/trans/controlflow.rs index 8004726d25e..6a7ffc1f3d3 100644 --- a/src/librustc_trans/trans/controlflow.rs +++ b/src/librustc_trans/trans/controlflow.rs @@ -339,7 +339,7 @@ pub fn trans_ret<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let mut bcx = bcx; let dest = match (fcx.llretslotptr.get(), retval_expr) { (Some(_), Some(retval_expr)) => { - let ret_ty = expr_ty(bcx, &*retval_expr); + let ret_ty = expr_ty_adjusted(bcx, &*retval_expr); expr::SaveIn(fcx.get_ret_slot(bcx, ty::FnConverging(ret_ty), "ret_slot")) } _ => expr::Ignore, diff --git a/src/test/run-pass/issue22346.rs b/src/test/run-pass/issue22346.rs new file mode 100644 index 00000000000..3193e5c5fc2 --- /dev/null +++ b/src/test/run-pass/issue22346.rs @@ -0,0 +1,17 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This used to cause an ICE because the retslot for the "return" had the wrong type +fn testcase<'a>() -> Box + 'a> { + return Box::new(range(0, 3).map(|i| { return i; })); +} + +fn main() { +}