]> git.proxmox.com Git - rustc.git/blame - src/test/ui/span/regions-infer-borrow-scope-within-loop.rs
New upstream version 1.25.0+dfsg1
[rustc.git] / src / test / ui / span / regions-infer-borrow-scope-within-loop.rs
CommitLineData
223e47cc
LB
1// Copyright 2012 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
223e47cc 11
1a4d82fc
JJ
12fn borrow<T>(x: &T) -> &T {x}
13
14fn foo<C, M>(mut cond: C, mut make_box: M) where
15 C: FnMut() -> bool,
16 M: FnMut() -> Box<isize>,
17{
18 let mut y: &isize;
223e47cc 19 loop {
1a4d82fc 20 let x = make_box();
223e47cc 21
970d7e83
LB
22 // Here we complain because the resulting region
23 // of this borrow is the fn body as a whole.
ff7c6d11
XL
24 y = borrow(&*x);
25 //~^ ERROR `*x` does not live long enough
223e47cc 26
970d7e83 27 assert_eq!(*x, *y);
223e47cc
LB
28 if cond() { break; }
29 }
30 assert!(*y != 0);
31}
32
33fn main() {}