Skip to content

Commit

Permalink
Apply adjustments to the retslot type in trans_ret
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dotdash committed Feb 15, 2015
1 parent b6d91a2 commit 109e118
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/controlflow.rs
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions 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 <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.

// This used to cause an ICE because the retslot for the "return" had the wrong type
fn testcase<'a>() -> Box<Iterator<Item=usize> + 'a> {
return Box::new(range(0, 3).map(|i| { return i; }));
}

fn main() {
}

0 comments on commit 109e118

Please sign in to comment.