Skip to content

Flag non-lowercase string literals in match expression on .to_lowercase() #7440

@kangalio

Description

@kangalio

What it does

Detect match statements of form str_variable.to_lowercase() with non-lowercase string literals as match arms. Should also apply to to_ascii_lowercase, to_uppercase, and to_ascii_uppercase.

Categories (optional)

  • Kind: clippy::correctness

The flagged match arm in the original code wouldn't ever be triggered, which is likely a bug in the program.

Drawbacks

None.

Example

match &*kind.to_ascii_lowercase() {
    "foo" => {},
    "Bar" => {},
    _ => {},
}

Should be written as:

match &*kind.to_ascii_lowercase() {
    "foo" => {},
    "bar" => {},
    _ => {},
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions