-
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
redundant_closure
false positive when interacting with FnMut
closures
#8098
Comments
I think the correct fix-it here is to insert a (mutable) reference to the closure? So that Also given that this is quick-fixable, I think the false-positive label should be removed and suggestion-causes-error applied. This is a true positive lint, but the wrong solution is applied when a correct one exists. |
@rben01 I think |
@guswynn In my opinion, if a beginner is already using the Also |
@rben01 hmm, I suppose I haven't thought of that parallel, that is fairly convincing! |
I am constantly running into this when browsing existing codebases. I'm personally in favor of the
The same issue also exists for Fn wrappers (in which case the corresponding fix is a non-mutable reference) but Fn is less commonplace which is presumably why there are fewer reports for that. |
The |
This was confusing at first (Why do I need to make my |
* Check feature_set for enable_partitioned_epoch_reward * Keep common variable outside if case * Keep common early return out of if case, since the first_slot_in_epoch must exist for partiion PDA to exist * Get and parse epoch partition data PDA * Find partition index for all addresses * Pull relevant blocks and get rewards * Reuse ordering and reformatting * Remove feature deactivation from TestValidator * Restore rewards iteration in first block in epoch for feature case to catch Voting rewards * Add fn get_reward_map helper to dedupe code * No need to start 2nd get_block_with_limit call with first block again * Replace filter_map to parameterize RewardType filter expression * Weird thing to make clippy and compiler agree (rust-lang/rust-clippy#8098) * Use activated_slot to ensure the right approach for past rewards epochs
* Check feature_set for enable_partitioned_epoch_reward * Keep common variable outside if case * Keep common early return out of if case, since the first_slot_in_epoch must exist for partiion PDA to exist * Get and parse epoch partition data PDA * Find partition index for all addresses * Pull relevant blocks and get rewards * Reuse ordering and reformatting * Remove feature deactivation from TestValidator * Restore rewards iteration in first block in epoch for feature case to catch Voting rewards * Add fn get_reward_map helper to dedupe code * No need to start 2nd get_block_with_limit call with first block again * Replace filter_map to parameterize RewardType filter expression * Weird thing to make clippy and compiler agree (rust-lang/rust-clippy#8098) * Use activated_slot to ensure the right approach for past rewards epochs (cherry picked from commit 22500c2)
…34960) Add rpc support for partitioned rewards (#34773) * Check feature_set for enable_partitioned_epoch_reward * Keep common variable outside if case * Keep common early return out of if case, since the first_slot_in_epoch must exist for partiion PDA to exist * Get and parse epoch partition data PDA * Find partition index for all addresses * Pull relevant blocks and get rewards * Reuse ordering and reformatting * Remove feature deactivation from TestValidator * Restore rewards iteration in first block in epoch for feature case to catch Voting rewards * Add fn get_reward_map helper to dedupe code * No need to start 2nd get_block_with_limit call with first block again * Replace filter_map to parameterize RewardType filter expression * Weird thing to make clippy and compiler agree (rust-lang/rust-clippy#8098) * Use activated_slot to ensure the right approach for past rewards epochs (cherry picked from commit 22500c2) Co-authored-by: Tyera <tyera@solana.com>
* Check feature_set for enable_partitioned_epoch_reward * Keep common variable outside if case * Keep common early return out of if case, since the first_slot_in_epoch must exist for partiion PDA to exist * Get and parse epoch partition data PDA * Find partition index for all addresses * Pull relevant blocks and get rewards * Reuse ordering and reformatting * Remove feature deactivation from TestValidator * Restore rewards iteration in first block in epoch for feature case to catch Voting rewards * Add fn get_reward_map helper to dedupe code * No need to start 2nd get_block_with_limit call with first block again * Replace filter_map to parameterize RewardType filter expression * Weird thing to make clippy and compiler agree (rust-lang/rust-clippy#8098) * Use activated_slot to ensure the right approach for past rewards epochs
Summary
This is related to #8073 but I believe it is sufficiently different:
Lint Name
redundant_closure
Reproducer
I tried this code:
I saw this happen:
Clippy suggests this closure is a false positive, but if you take its suggestion, it fails to compile:
because you are moving
logic
into the box, instead of moving a closure that references logic into itplayground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7d085db100dcb0f863e3e6f72dd3523a
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: