Skip to content

False positive: expl_impl_clone_on_copy with unsafe fields. #14558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimNN opened this issue Apr 5, 2025 · 0 comments · Fixed by #14559
Closed

False positive: expl_impl_clone_on_copy with unsafe fields. #14558

TimNN opened this issue Apr 5, 2025 · 0 comments · Fixed by #14559
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@TimNN
Copy link
Contributor

TimNN commented Apr 5, 2025

Summary

unsafe fields (still unstable, see rust-lang/rust#132922) cannot (currently) derive Clone.

(Feel free to close if this should wait until rust-lang/rust#132922 is closer to being stabilized).

Lint Name

expl_impl_clone_on_copy

Reproducer

I tried this code:

#![feature(unsafe_fields)]
#![allow(incomplete_features)]
#![warn(clippy::pedantic)]

pub struct Valid {
    pub unsafe actual: (),
}

unsafe impl Copy for Valid {}

impl Clone for Valid {
    #[inline]
    fn clone(&self) -> Self {
        *self
    }
}

I saw this happen:

warning: you are implementing `Clone` explicitly on a `Copy` type

I expected to see this happen: No warnings, since attempting to derive Clone produces a compiler error.

Version

rustc 1.88.0-nightly (17ffbc81a 2025-04-04)
binary: rustc
commit-hash: 17ffbc81a30c094193836a5d7f90dff273b5df93
commit-date: 2025-04-04
host: aarch64-apple-darwin
release: 1.88.0-nightly
LLVM version: 20.1.2

Additional Labels

No response

@TimNN TimNN added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 5, 2025
@samueltardieu samueltardieu self-assigned this Apr 6, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 12, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants