Skip to content

Commit 33ec4e4

Browse files
committed
make noop_method_call warn by default
1 parent cec34a4 commit 33ec4e4

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

compiler/rustc_lint/src/noop_method_call.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ declare_lint! {
1818
///
1919
/// ```rust
2020
/// # #![allow(unused)]
21-
/// #![warn(noop_method_call)]
2221
/// struct Foo;
2322
/// let foo = &Foo;
2423
/// let clone: &Foo = foo.clone();
@@ -34,7 +33,7 @@ declare_lint! {
3433
/// calling `clone` on a `&T` where `T` does not implement clone, actually doesn't do anything
3534
/// as references are copy. This lint detects these calls and warns the user about them.
3635
pub NOOP_METHOD_CALL,
37-
Allow,
36+
Warn,
3837
"detects the use of well-known noop methods"
3938
}
4039

tests/ui/issues/issue-11820.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// run-pass
22
// pretty-expanded FIXME #23616
33

4+
#![allow(noop_method_call)]
5+
46
struct NoClone;
57

68
fn main() {

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// check-pass
22

33
#![allow(unused)]
4-
#![warn(noop_method_call)]
54

65
use std::borrow::Borrow;
76
use std::ops::Deref;

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

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,58 @@
11
warning: call to `.clone()` on a reference in this situation does nothing
2-
--> $DIR/noop-method-call.rs:16:71
2+
--> $DIR/noop-method-call.rs:15: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>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
8-
note: the lint level is defined here
9-
--> $DIR/noop-method-call.rs:4:9
10-
|
11-
LL | #![warn(noop_method_call)]
12-
| ^^^^^^^^^^^^^^^^
8+
= note: `#[warn(noop_method_call)]` on by default
139

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

2218
warning: call to `.deref()` on a reference in this situation does nothing
23-
--> $DIR/noop-method-call.rs:27:63
19+
--> $DIR/noop-method-call.rs:26:63
2420
|
2521
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
2622
| ^^^^^^^^ unnecessary method call
2723
|
2824
= note: the type `&PlainType<u32>` which `deref` is being called on is the same as the type returned from `deref`, so the method call does not do anything and can be removed
2925

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

3632
warning: call to `.borrow()` on a reference in this situation does nothing
37-
--> $DIR/noop-method-call.rs:35:66
33+
--> $DIR/noop-method-call.rs:34:66
3834
|
3935
LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
4036
| ^^^^^^^^^ unnecessary method call
4137
|
4238
= note: the type `&PlainType<u32>` which `borrow` is being called on is the same as the type returned from `borrow`, so the method call does not do anything and can be removed
4339

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

5046
warning: call to `.clone()` on a reference in this situation does nothing
51-
--> $DIR/noop-method-call.rs:48:19
47+
--> $DIR/noop-method-call.rs:47:19
5248
|
5349
LL | non_clone_type.clone();
5450
| ^^^^^^^^ unnecessary method call
5551
|
5652
= note: the type `&PlainType<T>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
5753

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

tests/ui/underscore-imports/cycle.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
// check-pass
44

5+
#![allow(noop_method_call)]
6+
57
mod x {
68
pub use crate::y::*;
79
pub use std::ops::Deref as _;

tests/ui/underscore-imports/hygiene.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// check-pass
44

55
#![feature(decl_macro)]
6+
#![allow(noop_method_call)]
67

78
mod x {
89
pub use std::ops::Deref as _;

0 commit comments

Comments
 (0)