What is the current status of guaranteed NRVO in Rust?

Hello, can you describe what status of NRVO in Rust today? Is it planned to make it a guarantee, so that unsafe code can rely on it, with pinning? Or maybe some core members are against it? Is there any work going on right now? Is there some [Pre-]RFC a about it? What are chances of a new one getting accepted?

Thank you!

Not party if the lang or compiler teams, but here is my understanding.

The general sentiment is against return value emplacement via a guaranteed optimization like N. This is based on the caveats seen in C++, namely that it can be difficult to enforce that NRVO or copy elision in general is being applied in a given case.

Instead they'd prefer some other way of accomplishing emplacement. Probably through a new language feature that has yet to be designed.

There are existing RFCs proposing solutions, some based on NRVO. But they've been open for a long time indicating there's not a ton of interest from the project (priorities elsewhere).

The big open question, as I understand it, is how to make it work nicely with Result and ?.

let x = foo(); is relatively easy, but let x = bar()?; is far more complex, and I don't think people want a solution that means you can't have errors.

AFAIK people would be happy for someone to show up with a comprehensive, workable, and reliable solution, but we don't know one yet.

Details: Tracking issue for placement new · Issue #27779 · rust-lang/rust · GitHub

6 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.