- 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 haveL-nurseryLint: Currently in the nursery groupLint: Currently in the nursery group
Description
Summary
I am doing some async code and put the message sending and clearing the dead channels together by using retain
for iteration, which made clippy think that the collection was never read from, since retain is usually used for modifying only, see code snippet attached.
Lint Name
collection_is_never_read
Reproducer
I tried this code:
tokio::spawn(async move { let mut users = Vec::<MessageSender>::new(); loop { select! { channel = channel_receiver.recv() => { users.push(channel.expect("The sender is kept as global state and lives as long as the application")); }, message = rx.recv() => { let message = message.expect("The sender is kept as global state and lives as long as the application"); users.retain(|user| user.send(message.clone()).is_ok()); } } } });
I saw this happen:
collection is never read
I expected to see this happen:
Nothing!
Version
rustc 1.73.0 (cc66ad468 2023-10-03) binary: rustc commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33 commit-date: 2023-10-03 host: x86_64-unknown-linux-gnu release: 1.73.0 LLVM version: 17.0.2
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 haveL-nurseryLint: Currently in the nursery groupLint: Currently in the nursery group