1 //@run-rustfix
2
3 #![allow(
4 unused,
5 clippy::redundant_clone,
6 clippy::deref_addrof,
7 clippy::no_effect,
8 clippy::unnecessary_operation,
9 clippy::vec_init_then_push,
10 clippy::toplevel_ref_arg,
11 clippy::needless_borrow
12 )]
13
14 use std::cell::RefCell;
15 use std::rc::{self, Rc};
16 use std::sync::{self, Arc};
17
main()18 fn main() {}
19
is_ascii(ch: char) -> bool20 fn is_ascii(ch: char) -> bool {
21 ch.is_ascii()
22 }
23
clone_on_copy() -> Option<(i32)>24 fn clone_on_copy() -> Option<(i32)> {
25 42.clone();
26
27 vec![1].clone(); // ok, not a Copy type
28 Some(vec![1]).clone(); // ok, not a Copy type
29 (&42).clone();
30
31 let rc = RefCell::new(0);
32 rc.borrow().clone();
33
34 let x = 0u32;
35 x.clone().rotate_left(1);
36
37 #[derive(Clone, Copy)]
38 struct Foo;
39 impl Foo {
40 fn clone(&self) -> u32 {
41 0
42 }
43 }
44 Foo.clone(); // ok, this is not the clone trait
45
46 macro_rules! m {
47 ($e:expr) => {{ $e }};
48 }
49 m!(42).clone();
50
51 struct Wrap([u32; 2]);
52 impl core::ops::Deref for Wrap {
53 type Target = [u32; 2];
54 fn deref(&self) -> &[u32; 2] {
55 &self.0
56 }
57 }
58 let x = Wrap([0, 0]);
59 x.clone()[0];
60
61 let x = 42;
62 let ref y = x.clone(); // ok, binds by reference
63 let ref mut y = x.clone(); // ok, binds by reference
64
65 // Issue #4348
66 let mut x = 43;
67 let _ = &x.clone(); // ok, getting a ref
68 'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate
69 is_ascii('z'.clone());
70
71 // Issue #5436
72 let mut vec = Vec::new();
73 vec.push(42.clone());
74
75 // Issue #9277
76 let opt: &Option<i32> = &None;
77 let value = opt.clone()?; // operator precedence needed (*opt)?
78 None
79 }
80