diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-09-11 11:59:05 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-09-11 12:00:56 -0700 |
| commit | a9b929dbb6b8e86ccedf96a207a6253c0af1d6c9 (patch) | |
| tree | 3cbdbb65cfff89c08732d95a32da59ddc60f682d /src/test | |
| parent | c8b0d667c30e0918714ac178edaed883c6a8132a (diff) | |
| download | rust-a9b929dbb6b8e86ccedf96a207a6253c0af1d6c9.tar.gz rust-a9b929dbb6b8e86ccedf96a207a6253c0af1d6c9.zip | |
librustc: Make sure region bounds on closures outlive calls to them.
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]
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/region-bound-on-closure-outlives-call.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs new file mode 100644 index 00000000000..13ab7acaf48 --- /dev/null +++ b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs @@ -0,0 +1,16 @@ +// Copyright 2014 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. + +fn call_rec(f: |uint| -> uint) -> uint { + (|x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f` +} + +fn main() {} + |
