-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
maybe we should skip everything that is either self
or anything that is inside a impl of fn clone_from()
?
cc @Kobzol @blyxyas @kpreid
Reproducer
I tried this code:
impl<V: Clone> Clone for MaybeReachable<V> {
fn clone(&self) -> Self {
match self {
MaybeReachable::Reachable(x) => MaybeReachable::Reachable(x.clone()),
MaybeReachable::Unreachable => MaybeReachable::Unreachable,
}
}
fn clone_from(&mut self, source: &Self) {
match (&mut *self, source) {
(MaybeReachable::Reachable(x), MaybeReachable::Reachable(y)) => {
x.clone_from(y);
}
//_ => *self = source.clone(), // original
_ => self.clone_from(source), // BOOM
}
}
}
I expected to see this happen:
Instead, this happened:
Version
rustc 1.79.0-nightly (ef4936510 2024-03-30)
binary: rustc
commit-hash: ef493651025db2d5c38225c12ef97fd832c00c4a
commit-date: 2024-03-30
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way