Skip to content

Commit 363213c

Browse files
committed
Clarify that RFC1520 only relates to libraries
1 parent b1f51b0 commit 363213c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

text/1521-copy-clone-semantics.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# Summary
77
[summary]: #summary
88

9-
With specialization on the way, we need to talk about the semantics of
10-
`<T as Clone>::clone() where T: Copy`.
9+
Clarify semantics of `Clone` so that users are permitted to assume that
10+
`<T as Clone>::clone() where T: Copy` is implemented by `memcpy`.
1111

1212
It's generally been an unspoken rule of Rust that a `clone` of a `Copy` type is
1313
equivalent to a `memcpy` of that type; however, that fact is not documented
@@ -34,15 +34,19 @@ compatible to upgrade to Clone in the future if demand is high enough."
3434
# Detailed design
3535
[design]: #detailed-design
3636

37-
Specify that `<T as Clone>::clone(t)` shall be equivalent to `ptr::read(t)`
38-
where `T: Copy, t: &T`. An implementation that does not uphold this *shall not*
39-
result in undefined behavior; `Clone` is not an `unsafe trait`.
37+
Specify that users may assume `<T as Clone>::clone(t)` to be equivalent to
38+
`ptr::read(t)` where `T: Copy, t: &T`. An implementation that does not uphold
39+
this *shall not* result in undefined behavior; `Clone` is not an `unsafe
40+
trait`.
4041

4142
Also add something like the following sentence to the documentation for the
4243
`Clone` trait:
4344

4445
"If `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to
45-
`let x = *y;`. Manual implementations must be careful to uphold this."
46+
`let x = *y;`. Manual implementations should be careful to uphold this
47+
invariant, as users *may* assume that it holds (however the compiler itself
48+
*will not* make that assumption when compiling calls to `Clone::clone`,
49+
guaranteeing that the relevant `clone` method is always invoked)."
4650

4751
# Drawbacks
4852
[drawbacks]: #drawbacks

0 commit comments

Comments
 (0)