![github-actions[bot]](/assets/img/avatar_default.png)
* Create rule S7428 * Update rule.adoc * Update metadata.json * Update metadata.json * Update metadata.json --------- Co-authored-by: sallaigy <sallaigy@users.noreply.github.com> Co-authored-by: Gyula Sallai <gyula.sallai@sonarsource.com>
33 lines
682 B
Plaintext
33 lines
682 B
Plaintext
|
|
== Why is this an issue?
|
|
Case mismatches in pattern arms make some arms unreachable, likely leading to logic errors that can be difficult to debug.
|
|
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
match &*text.to_ascii_lowercase() {
|
|
"foo" => {},
|
|
"Bar" => {}, // Noncompliant: This arm is unreachable.
|
|
_ => {},
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,rust,diff-id=1,diff-type=compliant]
|
|
----
|
|
match &*text.to_ascii_lowercase() {
|
|
"foo" => {},
|
|
"bar" => {},
|
|
_ => {},
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#match_str_case_mismatch
|