]> git.lizzy.rs Git - rust.git/blob - src/test/ui/higher-rank-trait-bounds/hrtb-identity-fn-borrows.rs
Rollup merge of #100462 - zohnannor:master, r=thomcc
[rust.git] / src / test / ui / higher-rank-trait-bounds / hrtb-identity-fn-borrows.rs
1 // Test that the `'a` in the where clause correctly links the region
2 // of the output to the region of the input.
3
4 trait FnLike<A,R> {
5     fn call(&self, arg: A) -> R;
6 }
7
8 fn call_repeatedly<F>(f: F)
9     where F : for<'a> FnLike<&'a isize, &'a isize>
10 {
11     // Result is stored: cannot re-assign `x`
12     let mut x = 3;
13     let y = f.call(&x);
14     x = 5; //~ ERROR cannot assign to `x` because it is borrowed
15
16     // Result is not stored: can re-assign `x`
17     let mut x = 3;
18     f.call(&x);
19     f.call(&x);
20     f.call(&x);
21     x = 5;
22     drop(y);
23 }
24
25 fn main() {
26 }