diff options
| author | Jack Wrenn <jack@wrenn.fyi> | 2024-12-06 17:11:36 +0000 |
|---|---|---|
| committer | Jack Wrenn <jack@wrenn.fyi> | 2024-12-07 20:50:00 +0000 |
| commit | 691aec2ef3b5758a9ab0d277e9f72bcbd21921ee (patch) | |
| tree | 73a59daef66240e261b961fd7caffa8cf86b5027 /tests/codegen/patchable-function-entry/patchable-function-entry-no-flag.rs | |
| parent | 2c205e1d4443cb965426ab64ac916cfadbe06fd5 (diff) | |
| download | rust-691aec2ef3b5758a9ab0d277e9f72bcbd21921ee.tar.gz rust-691aec2ef3b5758a9ab0d277e9f72bcbd21921ee.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/codegen/patchable-function-entry/patchable-function-entry-no-flag.rs')
0 files changed, 0 insertions, 0 deletions
