forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#6078 - ebroto:unnecessary_sort_by_take_2, r=p…
…hansch unnecessary sort by: avoid dereferencing the suggested closure parameter This change tries to simplify the solution for problematic cases but is less restrictive than rust-lang#6006. * We can't dereference shared references to non-Copy types, so the new suggestion does not do that. Note that this implies that the suggested closure parameter will be a reference. * We can't take a reference to the closure parameter in the returned key, so we don't lint in those cases. This can happen either because the key borrows from the parameter (e.g. `|a| a.borrows()`), or because we suggest `|a| Reverse(a)`. If we did we would hit this error: ``` error: lifetime may not live long enough --> /home/ebroto/src/ebroto-clippy/tests/ui/unnecessary_sort_by.fixed:19:25 | 19 | vec.sort_by_key(|b| Reverse(b)); | -- ^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | || | |return type of closure is Reverse<&'2 isize> | has type `&'1 isize` error: aborting due to previous error ``` Note that Clippy does not currently have the (MIR-based) machinery necessary to check that what is borrowed is actually the closure parameter. changelog: [`unnecessary_sort_by`]: avoid dereferencing the suggested closure parameter Fixes rust-lang#6001
- Loading branch information
Showing
4 changed files
with
81 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters