Comments (4)
#[derive(Clone)]
doesn't even implementclone_from()
and the defaultclone_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.
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.
Especially considering that
#[derive(Clone)]
doesn't even implementclone_from()
and the defaultclone_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.
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)
- `indexing_slicing` emitting errors on proc-macro code.
- compiler told me to file this ... HOT 2
- Following `manual_clamp` suggestion results in slower code HOT 5
- False positive HOT 2
- Use `ControlFlow` in more visitors HOT 1
- Borrow incorrectly handled when trying to simplify return statement HOT 3
- Clippy error this loop never actually loops when use loop with select! HOT 1
- `bare URLs` in `clippy::doc_markdown` lint should have a `Quick Fix` HOT 1
- Some warnings are not reported if rust-src component is not installed HOT 2
- [`needless_bool`] suggestion cause error when the `if` expression is a method caller
- assertions_on_constants should not trigger inside `const` blocks HOT 2
- index out of bounds when compiling my os HOT 6
- `redundant_closure` doesn't handle `Fn` HOT 1
- Error with latest nightly HOT 2
- lines().count() should warn in case of Err
- unnecessary_cast false positive when casting pointers to types with lifetime parameters
- False Negative of `clippy::manual_strip` HOT 4
- Lint against `HashMap`s where the key is not `Eq + Hash` HOT 1
- `implicit_return` false positive inside `tauri::command` macro
- internal error: relating different kinds: `jni::objects::JObject<'?14> '?1`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-clippy.