]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-bad-nested-calls-move.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / 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
5
6 fn rewrite(v: &mut Box<usize>) -> usize {
7     *v = Box::new(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::new(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::new(1);
30     add(
31         &*a,
32         a); //~ ERROR cannot move
33 }
34
35 fn main() {}