diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:03:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:03:36 +0000 |
commit | 17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch) | |
tree | 3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /src/tools/clippy/tests/ui/collapsible_str_replace.rs | |
parent | Adding upstream version 1.64.0+dfsg1. (diff) | |
download | rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.tar.xz rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.zip |
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/collapsible_str_replace.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/collapsible_str_replace.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.rs b/src/tools/clippy/tests/ui/collapsible_str_replace.rs new file mode 100644 index 000000000..e3e25c414 --- /dev/null +++ b/src/tools/clippy/tests/ui/collapsible_str_replace.rs @@ -0,0 +1,76 @@ +// 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', "l").replace('u', "l"); + + let _ = "hesuo worpd".replace('s', l).replace('u', l); + + let _ = "hesuo worpd".replace('s', "l").replace('u', "l").replace('p', "l"); + + let _ = "hesuo worpd" + .replace('s', "l") + .replace('u', "l") + .replace('p', "l") + .replace('d', "l"); + + let _ = "hesuo world".replace(s, "l").replace('u', "l"); + + let _ = "hesuo worpd".replace(s, "l").replace('u', "l").replace('p', "l"); + + let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace('p', "l"); + + let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace(p, "l"); + + let _ = "hesuo worlp".replace('s', "l").replace('u', "l").replace('p', "d"); + + let _ = "hesuo worpd".replace('s', "x").replace('u', "l").replace('p', "l"); + + // Note: Future iterations could lint `replace(|c| matches!(c, "su" | 'd' | 'p'), "l")` + let _ = "hesudo worpd".replace("su", "l").replace('d', "l").replace('p', "l"); + + let _ = "hesudo worpd".replace(d, "l").replace('p', "l").replace("su", "l"); + + let _ = "hesuo world".replace(get_filter(), "l").replace('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()); +} |