]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/no_effect_replace.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / no_effect_replace.rs
1 #![warn(clippy::no_effect_replace)]
2
3 fn main() {
4 let _ = "12345".replace('1', "1");
5 let _ = "12345".replace("12", "12");
6 let _ = String::new().replace("12", "12");
7
8 let _ = "12345".replacen('1', "1", 1);
9 let _ = "12345".replacen("12", "12", 1);
10 let _ = String::new().replacen("12", "12", 1);
11
12 let _ = "12345".replace("12", "22");
13 let _ = "12345".replacen("12", "22", 1);
14
15 let mut x = X::default();
16 let _ = "hello".replace(&x.f(), &x.f());
17 let _ = "hello".replace(&x.f(), &x.ff());
18
19 let _ = "hello".replace(&y(), &y());
20 let _ = "hello".replace(&y(), &z());
21
22 let _ = Replaceme.replace("a", "a");
23 }
24
25 #[derive(Default)]
26 struct X {}
27
28 impl X {
29 fn f(&mut self) -> String {
30 "he".to_string()
31 }
32
33 fn ff(&mut self) -> String {
34 "hh".to_string()
35 }
36 }
37
38 fn y() -> String {
39 "he".to_string()
40 }
41
42 fn z() -> String {
43 "hh".to_string()
44 }
45
46 struct Replaceme;
47 impl Replaceme {
48 pub fn replace(&mut self, a: &str, b: &str) -> Self {
49 Self
50 }
51 }