Files
rust/compiler/rustc_middle/src/ty
León Orell Valerian Liehr 3eaa785daa Rollup merge of #134008 - jswrenn:unsafe-fields-copy, r=compiler-errors
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 entail `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

r? ```@compiler-errors```
2024-12-10 13:51:10 +01:00
..
2024-11-22 16:55:28 +00:00
2024-07-29 08:26:52 +10:00
2024-12-09 21:55:13 +00:00
2024-11-23 13:52:54 +01:00
2024-12-07 22:18:51 +00:00
2024-07-07 11:28:01 -04:00
2024-07-29 08:26:52 +10:00
2024-10-30 16:23:16 +00:00
2024-11-28 10:40:58 +01:00
2024-12-06 16:42:09 -05:00
2024-12-09 21:55:01 +00:00
2024-07-29 08:26:52 +10:00
2024-11-04 04:45:52 +00:00
2024-11-23 13:52:54 +01:00
2024-12-06 16:42:09 -05:00