]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-bad-nested-calls-move.rs
Apply suggestions from code review
[rust.git] / src / test / ui / borrowck / borrowck-bad-nested-calls-move.rs
1 // Test that we detect nested calls that could free pointers evaluated
2 // for earlier arguments.
3
4 #![feature(box_syntax)]
5
6 fn rewrite(v: &mut Box<usize>) -> usize {
7     *v = box 22;
8     **v
9 }
10
11 fn add(v: &usize, w: Box<usize>) -> usize {
12     *v + *w
13 }
14
15 fn implicit() {
16     let mut a: Box<_> = box 1;
17
18     // Note the danger here:
19     //
20     //    the pointer for the first argument has already been
21     //    evaluated, but it gets moved when evaluating the second
22     //    argument!
23     add(
24         &*a,
25         a); //~ ERROR cannot move
26 }
27
28 fn explicit() {
29     let mut a: Box<_> = box 1;
30     add(
31         &*a,
32         a); //~ ERROR cannot move
33 }
34
35 fn main() {}