about summary refs log tree commit diff
path: root/tests/rustdoc-ui/coverage/doc-examples.rs
diff options
context:
space:
mode:
authorJack Wrenn <jack@wrenn.fyi>2024-12-06 17:11:36 +0000
committerJack Wrenn <jack@wrenn.fyi>2024-12-07 20:50:00 +0000
commitcfee37d35872763f3af97da66081979f91141145 (patch)
tree7cd8de7ee1ab8043fe4ddd015960de5f848e87a5 /tests/rustdoc-ui/coverage/doc-examples.rs
parent7cc19d7d1f3aa95359ca95d795291e72ad14d61e (diff)
downloadrust-cfee37d35872763f3af97da66081979f91141145.tar.gz
rust-cfee37d35872763f3af97da66081979f91141145.zip
Make `Copy` unsafe to implement for ADTs with `unsafe` fields
As a rule, the application of `unsafe` to a declaration requires that use-sites
of that declaration also require `unsafe`. For example, a field declared
`unsafe` may only be read in the lexical context of an `unsafe` block.

For nearly all safe traits, the safety obligations of fields are explicitly
discharged when they are mentioned in method definitions. For example,
idiomatically implementing `Clone` (a safe trait) for a type with unsafe fields
will require `unsafe` to clone those fields.

Prior to this commit, `Copy` violated this rule. The trait is marked safe, and
although it has no explicit methods, its implementation permits reads of `Self`.

This commit resolves this by making `Copy` conditionally safe to implement. It
remains safe to implement for ADTs without unsafe fields, but unsafe to
implement for ADTs with unsafe fields.

Tracking: #132922
Diffstat (limited to 'tests/rustdoc-ui/coverage/doc-examples.rs')
0 files changed, 0 insertions, 0 deletions