Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kangalio opened this issue Jul 6, 2021 · 1 comment · Fixed by #7806
Closed

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

kangalio opened this issue Jul 6, 2021 · 1 comment · Fixed by #7806
Assignees
Labels
A-lint Area: New lints

Comments

@kangalio
Copy link

kangalio commented Jul 6, 2021

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" => {},
    _ => {},
}
@kangalio kangalio added the A-lint Area: New lints label Jul 6, 2021
@Serial-ATA
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants