You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #121471 - estebank:lint-clone, r=TaKO8Ki
When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`
CC #40699.
```
warning: call to `.clone()` on a reference in this situation does nothing
--> $DIR/noop-method-call.rs:23:71
|
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
| ^^^^^^^^
|
= note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
help: remove this redundant call
|
LL - let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
LL + let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref;
|
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
|
LL + #[derive(Clone)]
LL | struct PlainType<T>(T);
|
```
Copy file name to clipboardExpand all lines: compiler/rustc_lint/messages.ftl
+1
Original file line number
Diff line number
Diff line change
@@ -429,6 +429,7 @@ lint_non_upper_case_global = {$sort} `{$name}` should have an upper case name
429
429
lint_noop_method_call = call to `.{$method}()` on a reference in this situation does nothing
430
430
.suggestion = remove this redundant call
431
431
.note = the type `{$orig_ty}` does not implement `{$trait_}`, so calling `{$method}` on `&{$orig_ty}` copies the reference, which does not do anything and can be removed
432
+
.derive_suggestion = if you meant to clone `{$orig_ty}`, implement `Clone` for it
432
433
433
434
lint_only_cast_u8_to_char = only `u8` can be cast into `char`
warning: call to `.clone()` on a reference in this situation does nothing
11
-
--> $DIR/noop-method-call.rs:18:21
11
+
--> $DIR/noop-method-call.rs:17:21
12
12
|
13
13
LL | let _ = &encoded.clone();
14
14
| ^^^^^^^^ help: remove this redundant call
15
15
|
16
16
= note: the type `[u8]` does not implement `Clone`, so calling `clone` on `&[u8]` copies the reference, which does not do anything and can be removed
17
17
18
18
warning: call to `.clone()` on a reference in this situation does nothing
19
-
--> $DIR/noop-method-call.rs:24:71
19
+
--> $DIR/noop-method-call.rs:23:71
20
20
|
21
21
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
22
-
| ^^^^^^^^ help: remove this redundant call
22
+
| ^^^^^^^^
23
23
|
24
24
= note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
25
+
help: remove this redundant call
26
+
|
27
+
LL - let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
28
+
LL + let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref;
29
+
|
30
+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
31
+
|
32
+
LL + #[derive(Clone)]
33
+
LL | struct PlainType<T>(T);
34
+
|
25
35
26
36
warning: call to `.deref()` on a reference in this situation does nothing
27
-
--> $DIR/noop-method-call.rs:32:63
37
+
--> $DIR/noop-method-call.rs:31:63
28
38
|
29
39
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
30
-
| ^^^^^^^^ help: remove this redundant call
40
+
| ^^^^^^^^
31
41
|
32
42
= note: the type `PlainType<u32>` does not implement `Deref`, so calling `deref` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
43
+
help: remove this redundant call
44
+
|
45
+
LL - let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
46
+
LL + let non_deref_type_deref: &PlainType<u32> = non_deref_type;
47
+
|
48
+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
49
+
|
50
+
LL + #[derive(Clone)]
51
+
LL | struct PlainType<T>(T);
52
+
|
33
53
34
54
warning: call to `.borrow()` on a reference in this situation does nothing
35
-
--> $DIR/noop-method-call.rs:36:66
55
+
--> $DIR/noop-method-call.rs:35:66
36
56
|
37
57
LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
38
-
| ^^^^^^^^^ help: remove this redundant call
58
+
| ^^^^^^^^^
39
59
|
40
60
= note: the type `PlainType<u32>` does not implement `Borrow`, so calling `borrow` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
61
+
help: remove this redundant call
62
+
|
63
+
LL - let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
64
+
LL + let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type;
65
+
|
66
+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
67
+
|
68
+
LL + #[derive(Clone)]
69
+
LL | struct PlainType<T>(T);
70
+
|
41
71
42
72
warning: call to `.clone()` on a reference in this situation does nothing
43
-
--> $DIR/noop-method-call.rs:45:19
73
+
--> $DIR/noop-method-call.rs:44:19
44
74
|
45
75
LL | non_clone_type.clone();
46
-
| ^^^^^^^^ help: remove this redundant call
76
+
| ^^^^^^^^
47
77
|
48
78
= note: the type `PlainType<T>` does not implement `Clone`, so calling `clone` on `&PlainType<T>` copies the reference, which does not do anything and can be removed
79
+
help: remove this redundant call
80
+
|
81
+
LL - non_clone_type.clone();
82
+
LL + non_clone_type;
83
+
|
84
+
help: if you meant to clone `PlainType<T>`, implement `Clone` for it
85
+
|
86
+
LL + #[derive(Clone)]
87
+
LL | struct PlainType<T>(T);
88
+
|
49
89
50
90
warning: call to `.clone()` on a reference in this situation does nothing
51
-
--> $DIR/noop-method-call.rs:50:19
91
+
--> $DIR/noop-method-call.rs:49:19
52
92
|
53
93
LL | non_clone_type.clone();
54
-
| ^^^^^^^^ help: remove this redundant call
94
+
| ^^^^^^^^
55
95
|
56
96
= note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
97
+
help: remove this redundant call
98
+
|
99
+
LL - non_clone_type.clone();
100
+
LL + non_clone_type;
101
+
|
102
+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
0 commit comments