]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #6006 - ebroto:6001_unnecessary_sort_by, r=Manishearth
authorbors <bors@rust-lang.org>
Sun, 6 Sep 2020 22:37:46 +0000 (22:37 +0000)
committerbors <bors@rust-lang.org>
Sun, 6 Sep 2020 22:37:46 +0000 (22:37 +0000)
Restrict unnecessary_sort_by to non-reference, Copy types

`Vec::sort_by_key` closure parameter is `F: FnMut(&T) -> K`. The lint's suggestion destructures the `T` parameter; this was probably done to avoid different unnamed lifetimes when `K = Reverse<&T>`.

This change fixes two issues:
* Destructuring T when T is non-reference requires the type to be Copy, otherwise we would try to move from a shared reference. We make sure `T: Copy` holds.
* Make sure `T` is actually non-reference. I didn't go for destructuring multiple levels of references, as we would have to compensate in the closure body by removing derefs and maybe adding parens, which would add more complexity.

changelog: Restrict [`unnecessary_sort_by`] to non-reference, Copy types

Fixes #6001


Trivial merge