rust/compiler/rustc_hir_analysis/src
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
..
check Unconditionally error at definition if default field value has const errors 2024-12-09 21:58:00 +00:00
coherence Make Copy unsafe to implement for ADTs with unsafe fields 2024-12-07 20:50:00 +00:00
collect Introduce default_field_values feature 2024-12-09 21:55:01 +00:00
errors Clarify implicit captures for RPITIT 2024-10-10 11:46:51 -07:00
hir_ty_lowering Do not talk about "trait <Foo = Bar>" 2024-12-07 21:37:15 +00:00
impl_wf_check Fix const specialization 2024-12-02 22:21:53 +00:00
outlives Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
variance Add variances to RPITITs 2024-10-10 11:46:48 -07:00
autoderef.rs Swap Vec<PredicateObligation> to type alias 2024-10-12 15:17:08 +01:00
bounds.rs Merge HostPolarity and BoundConstness 2024-10-30 16:23:16 +00:00
check_unused.rs Remove #[macro_use] extern crate tracing from rustc_hir_analysis. 2024-08-30 17:14:59 +10:00
collect.rs Introduce default_field_values feature 2024-12-09 21:55:01 +00:00
constrained_generic_params.rs Remove #[macro_use] extern crate tracing from rustc_hir_analysis. 2024-08-30 17:14:59 +10:00
delegation.rs Effects cleanup 2024-10-26 10:19:07 +08:00
errors.rs Fix const specialization 2024-12-02 22:21:53 +00:00
hir_wf_check.rs uplift fold_regions to rustc_type_ir 2024-11-28 10:40:58 +01:00
impl_wf_check.rs nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
lib.rs Rollup merge of #132047 - compiler-errors:rbv-rtn-cleanup, r=cjgillot 2024-12-01 08:15:21 +01:00