mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-17 02:08:28 +00:00
73 lines
2.1 KiB
Rust
73 lines
2.1 KiB
Rust
// run-rustfix
|
|
|
|
#![warn(clippy::collapsible_str_replace)]
|
|
|
|
fn get_filter() -> char {
|
|
'u'
|
|
}
|
|
|
|
fn main() {
|
|
let d = 'd';
|
|
let p = 'p';
|
|
let s = 's';
|
|
let u = 'u';
|
|
let l = "l";
|
|
|
|
let mut iter = ["l", "z"].iter();
|
|
|
|
// LINT CASES
|
|
let _ = "hesuo worpd".replace(['s', 'u'], "l");
|
|
|
|
let _ = "hesuo worpd".replace(['s', 'u'], l);
|
|
|
|
let _ = "hesuo worpd".replace(['s', 'u', 'p'], "l");
|
|
|
|
let _ = "hesuo worpd"
|
|
.replace(['s', 'u', 'p', 'd'], "l");
|
|
|
|
let _ = "hesuo world".replace([s, 'u'], "l");
|
|
|
|
let _ = "hesuo worpd".replace([s, 'u', 'p'], "l");
|
|
|
|
let _ = "hesuo worpd".replace([s, u, 'p'], "l");
|
|
|
|
let _ = "hesuo worpd".replace([s, u, p], "l");
|
|
|
|
let _ = "hesuo worlp".replace(['s', 'u'], "l").replace('p', "d");
|
|
|
|
let _ = "hesuo worpd".replace('s', "x").replace(['u', 'p'], "l");
|
|
|
|
// Note: Future iterations could lint `replace(|c| matches!(c, "su" | 'd' | 'p'), "l")`
|
|
let _ = "hesudo worpd".replace("su", "l").replace(['d', 'p'], "l");
|
|
|
|
let _ = "hesudo worpd".replace([d, 'p'], "l").replace("su", "l");
|
|
|
|
let _ = "hesuo world".replace([get_filter(), 's'], "l");
|
|
|
|
// NO LINT CASES
|
|
let _ = "hesuo world".replace('s', "l").replace('u', "p");
|
|
|
|
let _ = "hesuo worpd".replace('s', "l").replace('p', l);
|
|
|
|
let _ = "hesudo worpd".replace('d', "l").replace("su", "l").replace('p', "l");
|
|
|
|
// Note: Future iterations of `collapsible_str_replace` might lint this and combine to `[s, u, p]`
|
|
let _ = "hesuo worpd".replace([s, u], "l").replace([u, p], "l");
|
|
|
|
let _ = "hesuo worpd".replace(['s', 'u'], "l").replace(['u', 'p'], "l");
|
|
|
|
let _ = "hesuo worpd".replace('s', "l").replace(['u', 'p'], "l");
|
|
|
|
let _ = "hesuo worpd".replace(['s', 'u', 'p'], "l").replace('r', "l");
|
|
|
|
let _ = "hesuo worpd".replace(['s', 'u', 'p'], l).replace('r', l);
|
|
|
|
let _ = "hesuo worpd".replace(['s', u, 'p'], "l").replace('r', "l");
|
|
|
|
let _ = "hesuo worpd".replace([s, u], "l").replace(p, "l");
|
|
|
|
// Regression test
|
|
let _ = "hesuo worpd"
|
|
.replace('u', iter.next().unwrap())
|
|
.replace('s', iter.next().unwrap());
|
|
}
|