You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's very easy to forget a return_ref on a non-copy type. On the other hand, returning a ref for a copy type may be undesired, but the performance consequences are often negligible.
Should we change the default for return_ref to be true and instead introduce a return_cloned.
Related: Should we introduce a return_deref? There have been a few occasions where I had an Option<T> and I ended up writing a manual accessor to get the deref behavior. That might also suggest that the syntax should be return(cloned), return(deref)return(ref)?
This is a rather subtle breaking change. We should change/decide on this before the first "stable" release.
The text was updated successfully, but these errors were encountered:
For the Copy case I'd also expect the compiler to change the ref-passing to copy passing in some occasions on its own so I think the "risk" there of that being less efficient is negligible. The bigger annoyance is that you in fact now have a reference to your type which means you need to deref it manually, but that can be worked around by well putting the marker attribute on it.
Generalizing it via return(<action>) seems to generally be a good move for future extensions imo. Either way 👍 from me for flipping the default, it sounds like what one would expect in terms of default behavior.
In an ideal world with specialization we could work around this via a trait with an assoc type that marks the return type and specializing on Copy to reduce the annotation burden entirely (I think).
This has come up in #718.
It's very easy to forget a
return_ref
on a non-copy type. On the other hand, returning a ref for acopy
type may be undesired, but the performance consequences are often negligible.Should we change the default for
return_ref
to be true and instead introduce areturn_cloned
.Related: Should we introduce a
return_deref
? There have been a few occasions where I had anOption<T>
and I ended up writing a manual accessor to get the deref behavior. That might also suggest that the syntax should bereturn(cloned)
,return(deref)
return(ref
)?This is a rather subtle breaking change. We should change/decide on this before the first "stable" release.
The text was updated successfully, but these errors were encountered: