Do not propose to auto-derive Clone in presence of unsafe fields (#14559)

`unsafe_fields` is an incomplete feature; comments have been put near
`#![expect(incomplete_features)]` to ensure that we revisit the
situation when the feature becomes complete.

changelog: [`expl_impl_clone_on_copy`]: do not lint in the presence of
`unsafe` fields

Fixes #14558
This commit is contained in:
Timo 2025-04-12 16:50:12 +00:00 committed by GitHub
commit 8dfcaa0590
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 10 deletions

View file

@ -349,6 +349,10 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
{
return;
}
// The presence of `unsafe` fields prevents deriving `Clone` automatically
if ty_adt.all_fields().any(|f| f.safety.is_unsafe()) {
return;
}
span_lint_and_note(
cx,