This commit is contained in:
2019-09-25 17:18:35 +02:00
parent 47b0ddf540
commit 77e737dfa2
14 changed files with 233 additions and 111 deletions

View File

@@ -0,0 +1,10 @@
error[E0502]: cannot borrow `vec` as mutable because it is also borrowed as immutable
--> src/main.rs:4:9
|
3 | for value in &vec {
| ----
| |
| immutable borrow occurs here
| immutable borrow later used here
4 | vec.push(*value);
| ^^^^^^^^^^^^^^^^ mutable borrow occurs here

View File

@@ -0,0 +1,3 @@
auto vec = std::vector<int> {1, 2, 3};
for (auto it = std::begin(vec); it < std::end(vec); it++)
vec.push_back(*it);

View File

@@ -0,0 +1,10 @@
fn func() {
let mut vec = vec![1, 2, 3];
let iter = vec.iter();
loop {
match iter.next() {
Some(x) => vec.push(x),
None => break,
}
}
}

View File

@@ -0,0 +1,3 @@
auto vec = std::vector<int> {1, 2, 3};
for (auto value: vec)
vec.push_back(value);

View File

@@ -0,0 +1,6 @@
fn func() {
let mut vec = vec![1, 2, 3];
for value in &vec {
vec.push(value);
}
}