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