-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add rc_buffer
lint for checking Rc<String> and friends
#6044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b5317f
Add rc_buffer lint for Rc<String> and other buffer types
rschoon 2dd7175
Apply rc_buffer lint to Arc<T>
rschoon d0ddbb9
Extend testing of rc_buffer lint
rschoon 2720085
Move rc_buffer lint into perf category
rschoon 6c056d3
Satisfy rc_buffer lint in Constant::Binary byte string by copying data
rschoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
#![warn(clippy::rc_buffer)] | ||
|
||
use std::cell::RefCell; | ||
use std::ffi::OsString; | ||
use std::path::PathBuf; | ||
use std::rc::Rc; | ||
|
||
struct S { | ||
yaahc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// triggers lint | ||
bad1: Rc<String>, | ||
bad2: Rc<PathBuf>, | ||
bad3: Rc<Vec<u8>>, | ||
bad4: Rc<OsString>, | ||
// does not trigger lint | ||
good1: Rc<RefCell<String>>, | ||
} | ||
|
||
// triggers lint | ||
fn func_bad1(_: Rc<String>) {} | ||
fn func_bad2(_: Rc<PathBuf>) {} | ||
fn func_bad3(_: Rc<Vec<u8>>) {} | ||
fn func_bad4(_: Rc<OsString>) {} | ||
// does not trigger lint | ||
fn func_good1(_: Rc<RefCell<String>>) {} | ||
|
||
fn main() {} |
This file contains hidden or 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>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:10:11 | ||
| | ||
LL | bad1: Rc<String>, | ||
| ^^^^^^^^^^ help: try: `Rc<str>` | ||
| | ||
= note: `-D clippy::rc-buffer` implied by `-D warnings` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:11:11 | ||
| | ||
LL | bad2: Rc<PathBuf>, | ||
| ^^^^^^^^^^^ help: try: `Rc<std::path::Path>` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:12:11 | ||
| | ||
LL | bad3: Rc<Vec<u8>>, | ||
| ^^^^^^^^^^^ help: try: `Rc<[u8]>` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:13:11 | ||
| | ||
LL | bad4: Rc<OsString>, | ||
| ^^^^^^^^^^^^ help: try: `Rc<std::ffi::OsStr>` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:19:17 | ||
| | ||
LL | fn func_bad1(_: Rc<String>) {} | ||
| ^^^^^^^^^^ help: try: `Rc<str>` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:20:17 | ||
| | ||
LL | fn func_bad2(_: Rc<PathBuf>) {} | ||
| ^^^^^^^^^^^ help: try: `Rc<std::path::Path>` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:21:17 | ||
| | ||
LL | fn func_bad3(_: Rc<Vec<u8>>) {} | ||
| ^^^^^^^^^^^ help: try: `Rc<[u8]>` | ||
|
||
error: usage of `Rc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer.rs:22:17 | ||
| | ||
LL | fn func_bad4(_: Rc<OsString>) {} | ||
| ^^^^^^^^^^^^ help: try: `Rc<std::ffi::OsStr>` | ||
|
||
error: aborting due to 8 previous errors | ||
|
This file contains hidden or 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,25 @@ | ||
#![warn(clippy::rc_buffer)] | ||
|
||
use std::ffi::OsString; | ||
use std::path::PathBuf; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
struct S { | ||
// triggers lint | ||
bad1: Arc<String>, | ||
bad2: Arc<PathBuf>, | ||
bad3: Arc<Vec<u8>>, | ||
bad4: Arc<OsString>, | ||
// does not trigger lint | ||
good1: Arc<Mutex<String>>, | ||
} | ||
|
||
// triggers lint | ||
fn func_bad1(_: Arc<String>) {} | ||
fn func_bad2(_: Arc<PathBuf>) {} | ||
fn func_bad3(_: Arc<Vec<u8>>) {} | ||
fn func_bad4(_: Arc<OsString>) {} | ||
// does not trigger lint | ||
fn func_good1(_: Arc<Mutex<String>>) {} | ||
|
||
fn main() {} |
This file contains hidden or 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 `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:9:11 | ||
| | ||
LL | bad1: Arc<String>, | ||
| ^^^^^^^^^^^ help: try: `Arc<str>` | ||
| | ||
= note: `-D clippy::rc-buffer` implied by `-D warnings` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:10:11 | ||
| | ||
LL | bad2: Arc<PathBuf>, | ||
| ^^^^^^^^^^^^ help: try: `Arc<std::path::Path>` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:11:11 | ||
| | ||
LL | bad3: Arc<Vec<u8>>, | ||
| ^^^^^^^^^^^^ help: try: `Arc<[u8]>` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:12:11 | ||
| | ||
LL | bad4: Arc<OsString>, | ||
| ^^^^^^^^^^^^^ help: try: `Arc<std::ffi::OsStr>` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:18:17 | ||
| | ||
LL | fn func_bad1(_: Arc<String>) {} | ||
| ^^^^^^^^^^^ help: try: `Arc<str>` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:19:17 | ||
| | ||
LL | fn func_bad2(_: Arc<PathBuf>) {} | ||
| ^^^^^^^^^^^^ help: try: `Arc<std::path::Path>` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:20:17 | ||
| | ||
LL | fn func_bad3(_: Arc<Vec<u8>>) {} | ||
| ^^^^^^^^^^^^ help: try: `Arc<[u8]>` | ||
|
||
error: usage of `Arc<T>` when T is a buffer type | ||
--> $DIR/rc_buffer_arc.rs:21:17 | ||
| | ||
LL | fn func_bad4(_: Arc<OsString>) {} | ||
| ^^^^^^^^^^^^^ help: try: `Arc<std::ffi::OsStr>` | ||
|
||
error: aborting due to 8 previous errors | ||
|
This file contains hidden or 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,12 @@ | ||
#![warn(clippy::rc_buffer)] | ||
|
||
use std::rc::Rc; | ||
|
||
struct String; | ||
|
||
struct S { | ||
// does not trigger lint | ||
good1: Rc<String>, | ||
} | ||
|
||
fn main() {} |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.