File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ // compile-flags:--borrowck=err
2
+
3
+ // Here we check that it is allowed to lend out an element of a
4
+ // (locally rooted) mutable, unique vector, and that we then prevent
5
+ // modifications to the contents.
6
+
7
+ fn takes_imm_elt ( _v : & int , f : fn ( ) ) {
8
+ f ( ) ;
9
+ }
10
+
11
+ fn has_mut_vec_and_does_not_try_to_change_it ( ) {
12
+ let v = [ mut 1 , 2 , 3 ] ;
13
+ takes_imm_elt ( & v[ 0 ] ) { ||
14
+ }
15
+ }
16
+
17
+ fn has_mut_vec_but_tries_to_change_it ( ) {
18
+ let v = [ mut 1 , 2 , 3 ] ;
19
+ takes_imm_elt ( & v[ 0 ] ) { || //! NOTE loan of mutable vec content granted here
20
+ v[ 1 ] = 4 ; //! ERROR assigning to mutable vec content prohibited due to outstanding loan
21
+ }
22
+ }
23
+
24
+ fn takes_const_elt ( _v : & const int , f : fn ( ) ) {
25
+ f ( ) ;
26
+ }
27
+
28
+ fn has_mut_vec_and_tries_to_change_it ( ) {
29
+ let v = [ mut 1 , 2 , 3 ] ;
30
+ takes_const_elt ( & const v[ 0 ] ) { ||
31
+ v[ 1 ] = 4 ;
32
+ }
33
+ }
34
+
35
+ fn main ( ) {
36
+ }
You can’t perform that action at this time.
0 commit comments