Hmm, I think I would say that (for the purposes of this proposal) returning anything that is neither of a) an ‘rvo literal’ and b) a require_rvo
function would cause compilation failure of a require_rvo
function.
Then you need to define ‘rvo literal’ which is something like:
StructOrEnum { name: <literal>, ... }
StructOrEnum(<literal>, ...)
[ <literal>, ... ]
-
[ <literal>; n]
(n can be normally valid expression) - one of https://doc.rust-lang.org/reference/expressions/literal-expr.html
- a const variable
- a dereferenced one of the above (where valid)
which looks basically like writing down the examples you’ve given that will be RVO optimised.
On reflection, I think you already need to enforce the above conditions to decide whether a function is able to return a DST - require_rvo
just allows you to opt in with statically sized types.