Merge pull request #2079 from rust-lang-nursery/ptr_arg-vs-capacity

avoid linting `ptr_arg` if `.capacity()` is called.
This commit is contained in:
Manish Goregaokar 2017-09-25 10:22:57 -07:00 committed by GitHub
commit 6842a522bb
8 changed files with 154 additions and 103 deletions

View file

@ -55,3 +55,15 @@ fn str_cloned(x: &String) -> String {
.clone();
x.clone()
}
fn false_positive_capacity(x: &Vec<u8>, y: &String) {
let a = x.capacity();
let b = y.clone();
let c = y.as_str();
}
fn false_positive_capacity_too(x: &String) -> String {
if x.capacity() > 1024 { panic!("Too large!"); }
x.clone()
}

View file

@ -28,11 +28,11 @@ help: change this to
|
40 | fn cloned(x: &[u8]) -> Vec<u8> {
| ^^^^^
help: change the `.clone()` to
help: change `x.clone()` to
|
41 | let e = x.to_owned();
| ^^^^^^^^^^^^
help: change the `.clone()` to
help: change `x.clone()` to
|
46 | x.to_owned()
| ^^^^^^^^^^^^
@ -47,18 +47,37 @@ help: change this to
|
49 | fn str_cloned(x: &str) -> String {
| ^^^^
help: change the `.clone` to
help: change `x.clone()` to
|
50 | let a = x.to_string();
| ^^^^^^^^^^^^^
help: change the `.clone` to
help: change `x.clone()` to
|
51 | let b = x.to_string();
| ^^^^^^^^^^^^^
help: change the `.clone` to
help: change `x.clone()` to
|
56 | x.to_string()
| ^^^^^^^^^^^^^
error: aborting due to 5 previous errors
error: writing `&String` instead of `&str` involves a new object where a slice will do.
--> $DIR/ptr_arg.rs:59:44
|
59 | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
| ^^^^^^^
|
help: change this to
|
59 | fn false_positive_capacity(x: &Vec<u8>, y: &str) {
| ^^^^
help: change `y.clone()` to
|
61 | let b = y.to_string();
| ^^^^^^^^^^^^^
help: change `y.as_str()` to
|
62 | let c = y;
| ^
error: aborting due to 6 previous errors