Skip to content

Commit f28d89f

Browse files
committed
Rollup merge of rust-lang#22366 - dotdash:ret_adjust, r=alexcrichton
Without the adjustments the retslot might have the wrong type, e.g. when the return value is implicitly coerced to a trait object. Fixes rust-lang#22346
2 parents e0477fa + 109e118 commit f28d89f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/librustc_trans/trans/controlflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub fn trans_ret<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
339339
let mut bcx = bcx;
340340
let dest = match (fcx.llretslotptr.get(), retval_expr) {
341341
(Some(_), Some(retval_expr)) => {
342-
let ret_ty = expr_ty(bcx, &*retval_expr);
342+
let ret_ty = expr_ty_adjusted(bcx, &*retval_expr);
343343
expr::SaveIn(fcx.get_ret_slot(bcx, ty::FnConverging(ret_ty), "ret_slot"))
344344
}
345345
_ => expr::Ignore,

src/test/run-pass/issue22346.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 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+
// This used to cause an ICE because the retslot for the "return" had the wrong type
12+
fn testcase<'a>() -> Box<Iterator<Item=usize> + 'a> {
13+
return Box::new(range(0, 3).map(|i| { return i; }));
14+
}
15+
16+
fn main() {
17+
}

0 commit comments

Comments
 (0)