-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
redundant_locals
seems to not allow rebinding a variable under the same name inside an async
block to move it into the future
Lint Name
redundant_locals
Reproducer
I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=22d86f4fc958069bc1f1a94855a63060
fn main() {
let do_not_move = String::new();
let things_to_move = vec!["a".to_string(), "b".to_string()];
let futures = things_to_move.into_iter().map(|move_me| async {
let move_me = move_me;
foo(&do_not_move, &move_me)
});
}
fn foo(a: &str, b: &str) {}
I saw this happen:
error: redundant redefinition of a binding `move_me`
--> src/main.rs:5:9
|
5 | let move_me = move_me;
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: `move_me` is initially defined here
--> src/main.rs:4:51
|
4 | let futures = things_to_move.into_iter().map(|move_me| async {
| ^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals
= note: `#[deny(clippy::redundant_locals)]` on by default
I expected to see this happen: no error
Version
Reproduces in playground; Rust 1.75.0, Clippy 0.1.75 (2023-12-21 82e1608)
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have