-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #5745 - montrivo:copy_on_clone, r=phansch
clone_on_copy - add machine applicability Fix #4826. Change the applicability of the lint clone_on_copy. Split a test file and run rustfix on the clone_on_copy part. changelog: clone_on_copy - add machine applicability
- Loading branch information
Showing
6 changed files
with
129 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// run-rustfix | ||
|
||
#![allow( | ||
unused, | ||
clippy::redundant_clone, | ||
clippy::deref_addrof, | ||
clippy::no_effect, | ||
clippy::unnecessary_operation | ||
)] | ||
|
||
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() { | ||
42; | ||
|
||
vec![1].clone(); // ok, not a Copy type | ||
Some(vec![1]).clone(); // ok, not a Copy type | ||
*(&42); | ||
|
||
let rc = RefCell::new(0); | ||
*rc.borrow(); | ||
|
||
// 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'); | ||
|
||
// Issue #5436 | ||
let mut vec = Vec::new(); | ||
vec.push(42); | ||
} |
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,40 @@ | ||
// run-rustfix | ||
|
||
#![allow( | ||
unused, | ||
clippy::redundant_clone, | ||
clippy::deref_addrof, | ||
clippy::no_effect, | ||
clippy::unnecessary_operation | ||
)] | ||
|
||
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() { | ||
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(); | ||
|
||
// 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()); | ||
} |
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,34 @@ | ||
error: using `clone` on a `Copy` type | ||
--> $DIR/clone_on_copy.rs:22:5 | ||
| | ||
LL | 42.clone(); | ||
| ^^^^^^^^^^ help: try removing the `clone` call: `42` | ||
| | ||
= note: `-D clippy::clone-on-copy` implied by `-D warnings` | ||
|
||
error: using `clone` on a `Copy` type | ||
--> $DIR/clone_on_copy.rs:26:5 | ||
| | ||
LL | (&42).clone(); | ||
| ^^^^^^^^^^^^^ help: try dereferencing it: `*(&42)` | ||
|
||
error: using `clone` on a `Copy` type | ||
--> $DIR/clone_on_copy.rs:29:5 | ||
| | ||
LL | rc.borrow().clone(); | ||
| ^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*rc.borrow()` | ||
|
||
error: using `clone` on a `Copy` type | ||
--> $DIR/clone_on_copy.rs:35:14 | ||
| | ||
LL | is_ascii('z'.clone()); | ||
| ^^^^^^^^^^^ help: try removing the `clone` call: `'z'` | ||
|
||
error: using `clone` on a `Copy` type | ||
--> $DIR/clone_on_copy.rs:39:14 | ||
| | ||
LL | vec.push(42.clone()); | ||
| ^^^^^^^^^^ help: try removing the `clone` call: `42` | ||
|
||
error: aborting due to 5 previous errors | ||
|
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