> Even if those values contain owned references into the heap, the programs can be trivially proven to be correct.
I don't think that's true. Passing data to a function when it's not a reference means that you're giving ownership to that function. How could you then pass it to another function (unless the first returned it again)? Once a function has ownership, it means nothing else has ownership of the data.
Basically, if you write a function that just takes a value, and doesn't take a reference, then you're telling your callers to give you ownership. If you don't want to take ownership, then just always accept a reference.
Maybe I'm misunderstanding the problem you're having. Do you have an example of another language that lets you do what you want?
> Passing data to a function when it's not a reference means that you're giving ownership to that function.
Only in Rust, but there's no apparent reason to move ownership. If Rust didn't move ownership during pass-by-value, it would still be trivial to prove the following code correct:
fn main() {
let x = String::new();
foo(x);
bar(x);
// x is destroyed
}
> Maybe I'm misunderstanding the problem you're having. Do you have an example of another language that lets you do what you want?
Here's the equivalent in C++:
int main() {
std::string x = "";
foo(x);
bar(x);
// x is destroyed
}
You can copy in Rust too. You just call .clone(), or if you want your type to always be copied, have it implement the Copy trait. In that case, it does exactly what you want.
But Rust is more explicit about copying in general, to make it harder for the performance cost to be hidden.
I don't think that's true. Passing data to a function when it's not a reference means that you're giving ownership to that function. How could you then pass it to another function (unless the first returned it again)? Once a function has ownership, it means nothing else has ownership of the data.
Basically, if you write a function that just takes a value, and doesn't take a reference, then you're telling your callers to give you ownership. If you don't want to take ownership, then just always accept a reference.
Maybe I'm misunderstanding the problem you're having. Do you have an example of another language that lets you do what you want?