Skip to content

Incorrect suggestion in "unnecessary-sort-by" #6001

@RalfJung

Description

@RalfJung

This code triggers the following suggestion:

error: use Vec::sort_by_key here instead
   --> src/report/mod.rs:223:5
    |
223 |     crates.sort_unstable_by(|a, b| a.id().cmp(&b.id()));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crates.sort_unstable_by_key(|&a| a.id())`
    |
    = note: `-D clippy::unnecessary-sort-by` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by

However, the suggested code does not work: &a is rejected as a pattern, it says I "cannot move out of a shared reference". using just a for the closure argument works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions