Not planned
Description
I tried this code:
struct A;
impl Clone for A {
fn clone(&self) -> Self {
println!("Basic clone");
Self
}
fn clone_from(&mut self, other: &Self) {
println!("Clone from");
*self = Self;
}
}
#[derive(Clone)]
struct B(A);
fn main() {
let b = B(A);
let mut bb = B(A);
bb.clone_from(&b);
}
I expected to see this happen: prints Clone from
Instead, this happened: prints Basic clone
I think, this can lead to little losses for types which have multiple vector and string fields.
Meta
rustc --version --verbose
:
rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0
rustc 1.63.0-nightly (5750a6aa2 2022-06-20)
binary: rustc
commit-hash: 5750a6aa2777382bf421b726f234da23f990a953
commit-date: 2022-06-20
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5
Activity
ChayimFriedman2 commentedon Jun 22, 2022
Dup #13281.
AngelicosPhosphoros commentedon Jun 22, 2022
Well, it was 5 years ago, this reasoning can be not true anymore.
LoganDark commentedon Jun 22, 2022
The reasoning was that it increased compile times too much. That reason will be just as good till the end of time because compiler speed is an important metric especially with how many
derive(Clone)
s are used in each crate.I'm not opposed to the idea of running another experiment, perhaps derives are faster now; but if it's still too slow then it's still too slow.
AngelicosPhosphoros commentedon Jun 22, 2022
Yup, I would run tests maybe today or tomorrow.
AngelicosPhosphoros commentedon Jun 22, 2022
Well, I wrote script and run tests.
Python script for generation and running tests
I had 2 times increase for compilation time if I have only
Clone
implemented but when I addedderive(Debug)
difference became less significant.See table:
Also, in original PR there weren't any perf runs and more throughput tests so I would make PR with changed Clone derive to run perf.
AngelicosPhosphoros commentedon Jun 22, 2022
I made some progress with implementation but it happened to be quite hard actually.
Current built-in derives implemented in the way that they support only immutable function parameters.
RalfJung commentedon Aug 24, 2023
Quoting from #98445 (comment)
So... should this issue be closed as "wontfix"?
fmease commentedon Jan 26, 2024
Closing as wontfix.
1 remaining item