Skip to content

Commit 59b2ca3

Browse files
committed
deny noop method call
1 parent b5e4915 commit 59b2ca3

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare_lint! {
3131
/// calling `clone` on a `&T` where `T` does not implement clone, actually doesn't do anything
3232
/// as references are copy. This lint detects these calls and warns the user about them.
3333
pub NOOP_METHOD_CALL,
34-
Warn,
34+
Deny,
3535
"detects the use of well-known noop methods"
3636
}
3737

tests/ui/lint/noop-method-call.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
22

33
#![allow(unused)]
4+
#![warn(noop_method_call)]
45

56
use std::borrow::Borrow;
67
use std::ops::Deref;

tests/ui/lint/noop-method-call.stderr

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,62 @@
11
warning: call to `.clone()` on a reference in this situation does nothing
2-
--> $DIR/noop-method-call.rs:15:71
2+
--> $DIR/noop-method-call.rs:16:71
33
|
44
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
55
| ^^^^^^^^ unnecessary method call
66
|
77
= 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
8-
= note: `#[warn(noop_method_call)]` on by default
8+
note: the lint level is defined here
9+
--> $DIR/noop-method-call.rs:4:9
10+
|
11+
LL | #![warn(noop_method_call)]
12+
| ^^^^^^^^^^^^^^^^
913

1014
warning: using `.clone()` on a double reference, which returns `&CloneType<u32>` instead of cloning the inner type
11-
--> $DIR/noop-method-call.rs:22:63
15+
--> $DIR/noop-method-call.rs:23:63
1216
|
1317
LL | let clone_type_ref_clone: &CloneType<u32> = clone_type_ref.clone();
1418
| ^^^^^^^^
1519
|
1620
= note: `#[warn(suspicious_double_ref_op)]` on by default
1721

1822
warning: call to `.deref()` on a reference in this situation does nothing
19-
--> $DIR/noop-method-call.rs:26:63
23+
--> $DIR/noop-method-call.rs:27:63
2024
|
2125
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
2226
| ^^^^^^^^ unnecessary method call
2327
|
2428
= 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
2529

2630
warning: using `.deref()` on a double reference, which returns `&PlainType<u32>` instead of dereferencing the inner type
27-
--> $DIR/noop-method-call.rs:30:63
31+
--> $DIR/noop-method-call.rs:31:63
2832
|
2933
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
3034
| ^^^^^^^^
3135

3236
warning: call to `.borrow()` on a reference in this situation does nothing
33-
--> $DIR/noop-method-call.rs:34:66
37+
--> $DIR/noop-method-call.rs:35:66
3438
|
3539
LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
3640
| ^^^^^^^^^ unnecessary method call
3741
|
3842
= 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
3943

4044
warning: using `.clone()` on a double reference, which returns `&str` instead of cloning the inner type
41-
--> $DIR/noop-method-call.rs:42:44
45+
--> $DIR/noop-method-call.rs:43:44
4246
|
4347
LL | let _v: Vec<&str> = xs.iter().map(|x| x.clone()).collect(); // could use `*x` instead
4448
| ^^^^^^^^
4549

4650
warning: call to `.clone()` on a reference in this situation does nothing
47-
--> $DIR/noop-method-call.rs:47:19
51+
--> $DIR/noop-method-call.rs:48:19
4852
|
4953
LL | non_clone_type.clone();
5054
| ^^^^^^^^ unnecessary method call
5155
|
5256
= 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
5357

5458
warning: call to `.clone()` on a reference in this situation does nothing
55-
--> $DIR/noop-method-call.rs:52:19
59+
--> $DIR/noop-method-call.rs:53:19
5660
|
5761
LL | non_clone_type.clone();
5862
| ^^^^^^^^ unnecessary method call

0 commit comments

Comments
 (0)