Skip to content

Commit 90304ed

Browse files
committed
auto merge of #17175 : pcwalton/rust/region-bounds-on-closures, r=huonw
This can break code like: fn call_rec(f: |uint| -> uint) -> uint { (|x| f(x))(call_rec(f)) } Change this code to use a temporary instead of violating the borrow rules: fn call_rec(f: |uint| -> uint) -> uint { let tmp = call_rec(|x| f(x)); f(tmp) } Closes #17144. [breaking-change] r? @huonw
2 parents a9cf198 + a9b929d commit 90304ed

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/librustc/middle/typeck/check/regionck.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,10 @@ fn constrain_callee(rcx: &mut Rcx,
10641064
};
10651065
rcx.fcx.mk_subr(infer::InvokeClosure(callee_expr.span),
10661066
call_region, region);
1067+
1068+
let region = closure_ty.bounds.region_bound;
1069+
rcx.fcx.mk_subr(infer::InvokeClosure(callee_expr.span),
1070+
call_region, region);
10671071
}
10681072
_ => {
10691073
// this should not happen, but it does if the program is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
fn call_rec(f: |uint| -> uint) -> uint {
12+
(|x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f`
13+
}
14+
15+
fn main() {}
16+

0 commit comments

Comments
 (0)