-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
127 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// check-pass | ||
// run-rustfix | ||
|
||
#![allow(unused)] | ||
|
||
use std::borrow::Borrow; | ||
use std::ops::Deref; | ||
|
||
struct PlainType<T>(T); | ||
|
||
#[derive(Clone)] | ||
struct CloneType<T>(T); | ||
|
||
fn check(mut encoded: &[u8]) { | ||
let _ = &mut encoded; | ||
//~^ WARN call to `.clone()` on a reference in this situation does nothing | ||
let _ = &encoded; | ||
//~^ WARN call to `.clone()` on a reference in this situation does nothing | ||
} | ||
|
||
fn main() { | ||
let non_clone_type_ref = &PlainType(1u32); | ||
let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref; | ||
//~^ WARN call to `.clone()` on a reference in this situation does nothing | ||
|
||
let clone_type_ref = &CloneType(1u32); | ||
let clone_type_ref_clone: CloneType<u32> = clone_type_ref.clone(); | ||
|
||
|
||
let non_deref_type = &PlainType(1u32); | ||
let non_deref_type_deref: &PlainType<u32> = non_deref_type; | ||
//~^ WARN call to `.deref()` on a reference in this situation does nothing | ||
|
||
let non_borrow_type = &PlainType(1u32); | ||
let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type; | ||
//~^ WARN call to `.borrow()` on a reference in this situation does nothing | ||
|
||
// Borrowing a &&T does not warn since it has collapsed the double reference | ||
let non_borrow_type = &&PlainType(1u32); | ||
let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow(); | ||
} | ||
|
||
fn generic<T>(non_clone_type: &PlainType<T>) { | ||
non_clone_type; | ||
//~^ WARN call to `.clone()` on a reference in this situation does nothing | ||
} | ||
|
||
fn non_generic(non_clone_type: &PlainType<u32>) { | ||
non_clone_type; | ||
//~^ WARN call to `.clone()` on a reference in this situation does nothing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,59 @@ | ||
warning: call to `.clone()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:15:71 | ||
--> $DIR/noop-method-call.rs:15:25 | ||
| | ||
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone(); | ||
| ^^^^^^^^ unnecessary method call | ||
LL | let _ = &mut encoded.clone(); | ||
| ^^^^^^^^ help: remove this redundant call | ||
| | ||
= 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 | ||
= 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 | ||
= note: `#[warn(noop_method_call)]` on by default | ||
|
||
warning: using `.clone()` on a double reference, which returns `&CloneType<u32>` instead of cloning the inner type | ||
--> $DIR/noop-method-call.rs:22:63 | ||
warning: call to `.clone()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:17:21 | ||
| | ||
LL | let clone_type_ref_clone: &CloneType<u32> = clone_type_ref.clone(); | ||
| ^^^^^^^^ | ||
LL | let _ = &encoded.clone(); | ||
| ^^^^^^^^ help: remove this redundant call | ||
| | ||
= note: `#[warn(suspicious_double_ref_op)]` on by default | ||
= 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 | ||
|
||
warning: call to `.deref()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:26:63 | ||
warning: call to `.clone()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:23:71 | ||
| | ||
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref(); | ||
| ^^^^^^^^ unnecessary method call | ||
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone(); | ||
| ^^^^^^^^ help: remove this redundant call | ||
| | ||
= 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 | ||
= 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 | ||
|
||
warning: using `.deref()` on a double reference, which returns `&PlainType<u32>` instead of dereferencing the inner type | ||
--> $DIR/noop-method-call.rs:30:63 | ||
warning: call to `.deref()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:31:63 | ||
| | ||
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref(); | ||
| ^^^^^^^^ | ||
| ^^^^^^^^ help: remove this redundant call | ||
| | ||
= 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 | ||
|
||
warning: call to `.borrow()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:34:66 | ||
--> $DIR/noop-method-call.rs:35:66 | ||
| | ||
LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow(); | ||
| ^^^^^^^^^ unnecessary method call | ||
| ^^^^^^^^^ help: remove this redundant call | ||
| | ||
= 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 | ||
|
||
warning: using `.clone()` on a double reference, which returns `&str` instead of cloning the inner type | ||
--> $DIR/noop-method-call.rs:42:44 | ||
| | ||
LL | let _v: Vec<&str> = xs.iter().map(|x| x.clone()).collect(); // could use `*x` instead | ||
| ^^^^^^^^ | ||
|
||
warning: call to `.clone()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:47:19 | ||
--> $DIR/noop-method-call.rs:44:19 | ||
| | ||
LL | non_clone_type.clone(); | ||
| ^^^^^^^^ unnecessary method call | ||
| ^^^^^^^^ help: remove this redundant call | ||
| | ||
= 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 | ||
|
||
warning: call to `.clone()` on a reference in this situation does nothing | ||
--> $DIR/noop-method-call.rs:52:19 | ||
--> $DIR/noop-method-call.rs:49:19 | ||
| | ||
LL | non_clone_type.clone(); | ||
| ^^^^^^^^ unnecessary method call | ||
| ^^^^^^^^ help: remove this redundant call | ||
| | ||
= 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 | ||
|
||
warning: 8 warnings emitted | ||
warning: 7 warnings emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters