-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lint suggestion: unnecessary_move #11721
Comments
An implementation for the lint described in rust-lang#11721
Add the `Span` of the `move` keyword to the HIR. This is required to implement a lint like the one described here: rust-lang/rust-clippy#11721
An implementation for the lint described in rust-lang#11721
Add the `Span` of the `move` keyword to the HIR. This is required to implement a lint like the one described here: rust-lang/rust-clippy#11721
An implementation for the lint described in rust-lang#11721
An implementation for the lint described in rust-lang#11721
An implementation for the lint described in rust-lang#11721
An implementation for the lint described in rust-lang#11721
An implementation for the lint described in rust-lang#11721
I think this is not a good principle to follow. A programmer should not be obligated to understand every nuance of the language's DWIM behaviors; they should be able to follow simpler principles which produce the right answer, where that does not harm readability, and Furthermore, this is at odds with reasonable consistency principles, like “always write spawn(move || job_1(...));
spawn(move || job_2(...)); than spawn(move || job_1(...));
spawn(|| job_2(...)); // this one has only by-move arguments I understand that this is being implemented as a Please consider putting this in the |
An implementation for the lint described in rust-lang#11721
An implementation for the lint described in rust-lang#11721
An implementation for the lint described in rust-lang#11721
When I initially added it, I wasn't sure of which category would fit it better, as it seems like a candidate for both |
It definitely doesn't make sense as a warn by default lint. Restriction seems fitting. The use case that made me think of that was when trying to force a closure to not implement A case where this lint would trigger: fn testing<T:Copy>(value: T) {
todo!()
}
fn main() {
let prevent_copy = String::new();
testing(move || {
let _ = prevent_copy;
println!("Copy");
})
} It compiles, but I initially expected it wouldn't. If you replace Maybe this is more about |
see discussion in rust-lang#11721
An implementation for the lint described in rust-lang#11721
see discussion in rust-lang#11721
An implementation for the lint described in rust-lang#11721
see discussion in rust-lang#11721
An implementation for the lint described in rust-lang#11721
see discussion in rust-lang#11721
What it does
Lints against uses of
move
before a closure orasync
block that captures nothing by reference.Advantage
This is likely the result of a mistake from the implementer, which does not have the proper intuition about how closure borrow their contents. Sometimes it can be hard to reason about it.
For example the developer might not realise that a capture that is passed by value is always captured by value.
Drawbacks
No response
Example
Could be written as:
Because the String is always captured by value, since it needs to be passed by value to
drop
.The text was updated successfully, but these errors were encountered: