Is there a way to get information about where in a Rust app moves are likely to be implemented by memory copy instead of a no-op? I know that the Rust compiler reserves the right to decide this differently based on optimization level and whim. But I'd like to know which cases I can expect to not be memcpys in a release, so that I can address those that might be memcpys by re-organizing the code. I'm only concerned with a few large-ish arrays I have.
I'm trying to get away from the C-style pass a pointer to raw memory and let the array get initialized there idiom and use the Rust preferred call-and-return-by-value style. But for some arrays that's making me wonder about memcpys I should try to avoid.
As others have said, read the assembly, but also the compiler is free to optimize the return value so even returning a large object doesn't necessarily entail a memcpy.
How do I turn on the unstable large assignments lint?
I can't get it to work in the playground:
This playground, when disassembled, shows a large memcpy in foo. But the large assignment lint doesn't show up - it builds without any warnings at all.
Is there a way to annotate a spot in Rust code so as to make it easy to find that spot in optimized assembly output, without impacting the Rust compiler's optimization decisions?