Skip to content

New lint: redundant_sort_by_key. #8212

@pmnoxx

Description

@pmnoxx

What it does

I saw an interesting bug today. Apparently the following code is valid.

[3,1,2].sort_by_key(|x|{x;}|);

The extra semicolon makes this function return (), which is valid, but this makes the sorting pointless.

Lint Name

useless_sort_by_key

Category

correctness

Advantage

  • This is likely a bug, and should be fixed. I had it happen to my code, once.
  • Or it can be just called redundant sort_by_key.

Drawbacks

  • I don't see any

Example

[3,1,2].sort_by_key(|x|{x;}|);

Could be written as:

That codes does nothing can be removed.
Or can be fixed, but it may be impossible to figure out what the user intended

[3,1,2].sort_by_key(|x|{x}|);

I think this should be marked as an potential error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-correctnessLint: Belongs in the correctness lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions