Giter Site home page Giter Site logo

Comments (4)

Alexendoo avatar Alexendoo commented on June 3, 2024

#[derive(Clone)] doesn't even implement clone_from() and the default clone_from() is implemented as *self = source.clone()

There are some false positives but they're from manual implementations in wrapper types (#12709). Directly at least types without a manual implementation of clone_from are ignored

from rust-clippy.

de-vri-es avatar de-vri-es commented on June 3, 2024

Ah, that's cool. I didn't know that.

But I still think clippy is suggesting to do a premature optimization. In code where this level of performance difference is truly important, the difference should be bench-marked.

I don't think this trade-off between absolute maximum possible performance and code readability is a proper one for the default configuration of clippy.

I got this warning from a String, but I really don't think the potential performance improvement is worth making the code less readable.

from rust-clippy.

kpreid avatar kpreid commented on June 3, 2024

Especially considering that #[derive(Clone)] doesn't even implement clone_from() and the default clone_from() is implemented as *self = source.clone():

Note that there's a catch-22 here: using clone_from() has little benefit because very few Clone implementations override it, and very few Clone implementations override it because it is so rarely used. I hoped that by creating assigning_clones, this cycle would be broken.

from rust-clippy.

de-vri-es avatar de-vri-es commented on June 3, 2024

That's true. But even if this gives a runtime performance improvement, I don't think this lint should be enabled by default. It favors a small performance gain over a big readability loss.

This kind of optimization may save a call to alloc and free in practise. If this is important enough, the compiler should try to figure this out and re-use the allocation behind the scenes (I think many C++ compilers do this nowadays?).

I really feel that telling people not to use the = operator for assigning values is the wrong thing to do as a default.

/edit: Reading the zulip conversation the consensus also seems to be to put it in pedantic? https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Meeting.202023-05-02/near/355185136

from rust-clippy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.