diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-12-10 13:51:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 13:51:10 +0100 |
| commit | 3eaa785daa92be680d8549c87f1b68b811904abd (patch) | |
| tree | a31f332d55a2720c2e215d0cc3a8d158e4b2bae0 /src/tools | |
| parent | ceaca6be471dffee50c5ded5fe923ec74395446a (diff) | |
| parent | 3ce35a4ec5f06828f908a018da083af5eb54301a (diff) | |
| download | rust-3eaa785daa92be680d8549c87f1b68b811904abd.tar.gz rust-3eaa785daa92be680d8549c87f1b68b811904abd.zip | |
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```
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index cd90d2f90f7..6f3f371a68d 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -200,6 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { cx.param_env, ty, traits::ObligationCause::dummy_with_span(span), + rustc_hir::Safety::Safe, ) .is_ok() { |
