The current document is
a
clone()
of this box's contents.
But in reality, its behavior is specialized, if the content impl Copy
, will not call clone
.
What is our expected behavior, should we modify the document or remove specialization?
The current document is
a
clone()
of this box's contents.
But in reality, its behavior is specialized, if the content impl Copy
, will not call clone
.
What is our expected behavior, should we modify the document or remove specialization?
This is relying on the semantics of RFC 1521, which led to this note in the Clone
docs:
Types that are
Copy
should have a trivial implementation ofClone
. More formally: ifT: Copy
,x: T
, andy: &T
, thenlet x = y.clone();
is equivalent tolet x = *y;
. Manual implementations should be careful to uphold this invariant; however, unsafe code must not rely on it to ensure memory safety.
So if you're doing anything in clone
that is observably different than a Copy
, then you are violating this expectation. That shouldn't cause any safety problems, as noted above, but you could see that dbg!
statements in your clone
aren't called if it was actually copied instead.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.