Update
This commit is contained in:
10
assets/dash-3d-implementation/undefined-behaviour-error.txt
Normal file
10
assets/dash-3d-implementation/undefined-behaviour-error.txt
Normal 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
|
||||
3
assets/dash-3d-implementation/undefined-behaviour-it.cpp
Normal file
3
assets/dash-3d-implementation/undefined-behaviour-it.cpp
Normal 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);
|
||||
10
assets/dash-3d-implementation/undefined-behaviour-it.rs
Normal file
10
assets/dash-3d-implementation/undefined-behaviour-it.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
3
assets/dash-3d-implementation/undefined-behaviour.cpp
Normal file
3
assets/dash-3d-implementation/undefined-behaviour.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
auto vec = std::vector<int> {1, 2, 3};
|
||||
for (auto value: vec)
|
||||
vec.push_back(value);
|
||||
6
assets/dash-3d-implementation/undefined-behaviour.rs
Normal file
6
assets/dash-3d-implementation/undefined-behaviour.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
fn func() {
|
||||
let mut vec = vec![1, 2, 3];
|
||||
for value in &vec {
|
||||
vec.push(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user