3 ms·
This sort of gets at the root of why using two operators wasn't great: you're basically forcing a human to annotate what a compiler already knows. It doesn't im
by steveklabnik 12y ago
This sort of gets at the root of why using two operators wasn't great: you're basically forcing a human to annotate what a compiler already knows. It doesn't improve the situation significantly, and just adds noise. It's sort of similar to why we don't force you to write out every single type.
I'm trying to find the blog post that had an example of the old syntax, but I can't at the moment :/
As you code in Rust, you sort of figure out what should be Copy and what shouldn't: can it be completely copied with a memcpy? Then it's Copy, or it should be. Does it contain a pointer to some sort of external resource? Than it shouldn't be.
And, once you've written some Rust, you know what 'use of moved value' is: it means the type moves, not copies. So the error _does_ tell you what's up, although it may not be 100% awesome for completely new people.
The error from my first program, trying to print `v` after:
hello.rs:5:22: 5:23 error: use of moved value: `v`
hello.rs:5 println!("{:?}", v);
^
note: in expansion of format_args!
<std macros>:2:25: 2:56 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
hello.rs:5:5: 5:25 note: expansion site
hello.rs:3:9: 3:11 note: `v` moved here because it has type `collections::vec::Vec<i32>`, which is moved by default
hello.rs:3 let v2 = v;
^~
hello.rs:3:9: 3:11 help: use `ref` to override
`ref` is sort of an awkward suggestion, but it does tell you, it's moved by default.