-
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 #5349 - jpospychala:useless_rc, r=Manishearth
useless Rc<Rc<T>>, Rc<Box<T>>, Rc<&T>, Box<&T> refers to #2394 changelog: Add lints for Rc<Rc<T>> and Rc<Box<T>> and Rc<&T>, Box<&T> this is based on top of another change #5310 so probably should go after that one.
- Loading branch information
Showing
10 changed files
with
259 additions
and
8 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
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
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,48 @@ | ||
// run-rustfix | ||
#![warn(clippy::all)] | ||
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] | ||
#![allow(clippy::blacklisted_name, unused_variables, dead_code)] | ||
|
||
use std::boxed::Box; | ||
use std::rc::Rc; | ||
|
||
pub struct MyStruct {} | ||
|
||
pub struct SubT<T> { | ||
foo: T, | ||
} | ||
|
||
pub enum MyEnum { | ||
One, | ||
Two, | ||
} | ||
|
||
// Rc<&T> | ||
|
||
pub fn test1<T>(foo: &T) {} | ||
|
||
pub fn test2(foo: &MyStruct) {} | ||
|
||
pub fn test3(foo: &MyEnum) {} | ||
|
||
pub fn test4_neg(foo: Rc<SubT<&usize>>) {} | ||
|
||
// Rc<Rc<T>> | ||
|
||
pub fn test5(a: Rc<bool>) {} | ||
|
||
// Rc<Box<T>> | ||
|
||
pub fn test6(a: Box<bool>) {} | ||
|
||
// Box<&T> | ||
|
||
pub fn test7<T>(foo: &T) {} | ||
|
||
pub fn test8(foo: &MyStruct) {} | ||
|
||
pub fn test9(foo: &MyEnum) {} | ||
|
||
pub fn test10_neg(foo: Box<SubT<&usize>>) {} | ||
|
||
fn main() {} |
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,48 @@ | ||
// run-rustfix | ||
#![warn(clippy::all)] | ||
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] | ||
#![allow(clippy::blacklisted_name, unused_variables, dead_code)] | ||
|
||
use std::boxed::Box; | ||
use std::rc::Rc; | ||
|
||
pub struct MyStruct {} | ||
|
||
pub struct SubT<T> { | ||
foo: T, | ||
} | ||
|
||
pub enum MyEnum { | ||
One, | ||
Two, | ||
} | ||
|
||
// Rc<&T> | ||
|
||
pub fn test1<T>(foo: Rc<&T>) {} | ||
|
||
pub fn test2(foo: Rc<&MyStruct>) {} | ||
|
||
pub fn test3(foo: Rc<&MyEnum>) {} | ||
|
||
pub fn test4_neg(foo: Rc<SubT<&usize>>) {} | ||
|
||
// Rc<Rc<T>> | ||
|
||
pub fn test5(a: Rc<Rc<bool>>) {} | ||
|
||
// Rc<Box<T>> | ||
|
||
pub fn test6(a: Rc<Box<bool>>) {} | ||
|
||
// Box<&T> | ||
|
||
pub fn test7<T>(foo: Box<&T>) {} | ||
|
||
pub fn test8(foo: Box<&MyStruct>) {} | ||
|
||
pub fn test9(foo: Box<&MyEnum>) {} | ||
|
||
pub fn test10_neg(foo: Box<SubT<&usize>>) {} | ||
|
||
fn main() {} |
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,52 @@ | ||
error: usage of `Rc<&T>` | ||
--> $DIR/redundant_allocation.rs:22:22 | ||
| | ||
LL | pub fn test1<T>(foo: Rc<&T>) {} | ||
| ^^^^^^ help: try: `&T` | ||
| | ||
= note: `-D clippy::redundant-allocation` implied by `-D warnings` | ||
|
||
error: usage of `Rc<&T>` | ||
--> $DIR/redundant_allocation.rs:24:19 | ||
| | ||
LL | pub fn test2(foo: Rc<&MyStruct>) {} | ||
| ^^^^^^^^^^^^^ help: try: `&MyStruct` | ||
|
||
error: usage of `Rc<&T>` | ||
--> $DIR/redundant_allocation.rs:26:19 | ||
| | ||
LL | pub fn test3(foo: Rc<&MyEnum>) {} | ||
| ^^^^^^^^^^^ help: try: `&MyEnum` | ||
|
||
error: usage of `Rc<Rc<T>>` | ||
--> $DIR/redundant_allocation.rs:32:17 | ||
| | ||
LL | pub fn test5(a: Rc<Rc<bool>>) {} | ||
| ^^^^^^^^^^^^ help: try: `Rc<bool>` | ||
|
||
error: usage of `Rc<Box<T>>` | ||
--> $DIR/redundant_allocation.rs:36:17 | ||
| | ||
LL | pub fn test6(a: Rc<Box<bool>>) {} | ||
| ^^^^^^^^^^^^^ help: try: `Box<bool>` | ||
|
||
error: usage of `Box<&T>` | ||
--> $DIR/redundant_allocation.rs:40:22 | ||
| | ||
LL | pub fn test7<T>(foo: Box<&T>) {} | ||
| ^^^^^^^ help: try: `&T` | ||
|
||
error: usage of `Box<&T>` | ||
--> $DIR/redundant_allocation.rs:42:19 | ||
| | ||
LL | pub fn test8(foo: Box<&MyStruct>) {} | ||
| ^^^^^^^^^^^^^^ help: try: `&MyStruct` | ||
|
||
error: usage of `Box<&T>` | ||
--> $DIR/redundant_allocation.rs:44:19 | ||
| | ||
LL | pub fn test9(foo: Box<&MyEnum>) {} | ||
| ^^^^^^^^^^^^ help: try: `&MyEnum` | ||
|
||
error: aborting due to 8 previous errors | ||
|