4 ms·
NRVO is a completely transparent optimization that Rust tries to do whenever possible. I don’t know what sort of case you can get into with object identity but
by lalaithion 4y ago
NRVO is a completely transparent optimization that Rust tries to do whenever possible. I don’t know what sort of case you can get into with object identity but I suspect it’s obviated by making moved-out-of values untouchable at compile time.
- gpderetta 4y agoC++ example: using array = std::array<int, 10>; array make(array* y) { array result = {...}; assert(&result != y); return result; } array x = make(&x); Normally in C++ distinct objects (result and x) have distinct addresses, so the assert would be guaranteed not to fire. But NRVO is explicitly allowed in the standard to violate this guarantee, so result can overlap with x. In rust you likely cannot get the address of the not-yet-constructed x, but it might be possible to construct equivalent examples.