Skip to content

New lint: Returning unit type when expecting Ord #5080

Closed
@Uriopass

Description

@Uriopass

I had a very weird bug today, I was trying to sort my list using a somewhat complicated key expression with sort_by_key, but no sorting was happening it was like getting a random order.

Turns out I had an extra semicolon at the end of my expression, making my key return () instead which implements Ord (always Equal).

Example:

vec.sort_by_key(|x| {
    some_function(some_expression(x));
                                  // ^---- extra semicolon here
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-correctnessLint: Belongs in the correctness lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions