mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
68 lines
1.9 KiB
Rust
68 lines
1.9 KiB
Rust
// run-rustfix
|
|
|
|
#![warn(clippy::collapsible_str_replace)]
|
|
|
|
fn get_filter() -> &'static str {
|
|
"u"
|
|
}
|
|
|
|
fn main() {
|
|
let misspelled = "hesuo worpd";
|
|
|
|
let p = 'p';
|
|
let s = 's';
|
|
let u = 'u';
|
|
let l = "l";
|
|
|
|
// LINT CASES
|
|
let _ = misspelled.replace('s', "l").replace('u', "l");
|
|
|
|
let _ = misspelled.replace('s', l).replace('u', l);
|
|
|
|
let _ = misspelled.replace('s', "l").replace('u', "l").replace('p', "l");
|
|
|
|
let _ = misspelled
|
|
.replace('s', "l")
|
|
.replace('u', "l")
|
|
.replace('p', "l")
|
|
.replace('d', "l");
|
|
|
|
// FALLBACK CASES
|
|
// If there are consecutive calls to `str::replace` and all or any chars are variables,
|
|
// recommend the fallback `misspelled.replace(&[s, u, p], "l")`
|
|
let _ = misspelled.replace(s, "l").replace('u', "l");
|
|
|
|
let _ = misspelled.replace(s, "l").replace('u', "l").replace('p', "l");
|
|
|
|
let _ = misspelled.replace(s, "l").replace(u, "l").replace('p', "l");
|
|
|
|
let _ = misspelled.replace(s, "l").replace(u, "l").replace(p, "l");
|
|
|
|
// NO LINT CASES
|
|
let _ = misspelled.replace('s', "l");
|
|
|
|
let _ = misspelled.replace(s, "l");
|
|
|
|
// If the consecutive `str::replace` calls have different `to` arguments, do not lint
|
|
let _ = misspelled.replace('s', "l").replace('u', "p");
|
|
|
|
let _ = misspelled.replace(&get_filter(), "l");
|
|
|
|
let _ = misspelled.replace(&['s', 'u', 'p'], "l");
|
|
|
|
let _ = misspelled.replace(&['s', 'u', 'p'], l);
|
|
|
|
let _ = misspelled.replace(&['s', 'u'], "l").replace(&['u', 'p'], "l");
|
|
|
|
let _ = misspelled.replace('s', "l").replace(&['u', 'p'], "l");
|
|
|
|
let _ = misspelled.replace(&['s', 'u'], "l").replace('p', "l");
|
|
|
|
let _ = misspelled.replace(&['s', u, 'p'], "l");
|
|
|
|
let _ = misspelled.replace(&[s, u, 'p'], "l");
|
|
|
|
let _ = misspelled.replace(&[s, u, p], "l");
|
|
|
|
let _ = misspelled.replace(&[s, u], "l").replace(&[u, p], "l");
|
|
}
|