Created
April 10, 2016 21:05
-
-
Save anonymous/0dcd62a61ce262fe1a49c8cc279b7526 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
// No good because we move v to v2 | |
// which creates a copy of the pointer | |
// which means we have two pointers | |
// to the content of the vector on the heap | |
// this violates safety guarantees | |
// by introducing a data race | |
// therefore Rust forbids using v after the move | |
// +---------+------+----------------+ | |
// | address | name | value | | |
// +---------+------+----------------+ | |
// | 1 | v2 | ->(2 ^ 30) - 1 | | |
// | 0 | v | ->(2 ^ 30) - 1 | | |
// +---------+------+----------------+ | |
let v = vec![1, 2, 3]; | |
let v2 = v; | |
println!("{:?}", v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment