mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
216 lines
7.1 KiB
Text
216 lines
7.1 KiB
Text
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:14:14
|
|
|
|
|
LL | fn do_vec(x: &Vec<i64>) {
|
|
| ^^^^^^^^^ help: change this to: `&[i64]`
|
|
|
|
|
= note: `-D clippy::ptr-arg` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]`
|
|
|
|
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:20:18
|
|
|
|
|
LL | fn do_vec_mut(x: &mut Vec<i64>) {
|
|
| ^^^^^^^^^^^^^ help: change this to: `&mut [i64]`
|
|
|
|
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:25:19
|
|
|
|
|
LL | fn do_vec_mut2(x: &mut Vec<i64>) {
|
|
| ^^^^^^^^^^^^^ help: change this to: `&mut [i64]`
|
|
|
|
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:31:14
|
|
|
|
|
LL | fn do_str(x: &String) {
|
|
| ^^^^^^^ help: change this to: `&str`
|
|
|
|
error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:36:18
|
|
|
|
|
LL | fn do_str_mut(x: &mut String) {
|
|
| ^^^^^^^^^^^ help: change this to: `&mut str`
|
|
|
|
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:41:15
|
|
|
|
|
LL | fn do_path(x: &PathBuf) {
|
|
| ^^^^^^^^ help: change this to: `&Path`
|
|
|
|
error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:46:19
|
|
|
|
|
LL | fn do_path_mut(x: &mut PathBuf) {
|
|
| ^^^^^^^^^^^^ help: change this to: `&mut Path`
|
|
|
|
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:55:18
|
|
|
|
|
LL | fn do_vec(x: &Vec<i64>);
|
|
| ^^^^^^^^^ help: change this to: `&[i64]`
|
|
|
|
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:69:14
|
|
|
|
|
LL | fn cloned(x: &Vec<u8>) -> Vec<u8> {
|
|
| ^^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn cloned(x: &[u8]) -> Vec<u8> {
|
|
LL |
|
|
LL ~ let e = x.to_owned();
|
|
LL | let f = e.clone(); // OK
|
|
LL | let g = x;
|
|
LL ~ let h = g.to_owned();
|
|
LL | let i = (e).clone();
|
|
LL ~ x.to_owned()
|
|
|
|
|
|
|
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:79:18
|
|
|
|
|
LL | fn str_cloned(x: &String) -> String {
|
|
| ^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn str_cloned(x: &str) -> String {
|
|
LL |
|
|
LL ~ let a = x.to_owned();
|
|
LL ~ let b = x.to_owned();
|
|
LL | let c = b.clone();
|
|
LL | let d = a.clone().clone().clone();
|
|
LL ~ x.to_owned()
|
|
|
|
|
|
|
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:88:19
|
|
|
|
|
LL | fn path_cloned(x: &PathBuf) -> PathBuf {
|
|
| ^^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn path_cloned(x: &Path) -> PathBuf {
|
|
LL |
|
|
LL ~ let a = x.to_path_buf();
|
|
LL ~ let b = x.to_path_buf();
|
|
LL | let c = b.clone();
|
|
LL | let d = a.clone().clone().clone();
|
|
LL ~ x.to_path_buf()
|
|
|
|
|
|
|
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:97:44
|
|
|
|
|
LL | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
|
|
| ^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn false_positive_capacity(x: &Vec<u8>, y: &str) {
|
|
LL |
|
|
LL | let a = x.capacity();
|
|
LL ~ let b = y.to_owned();
|
|
LL ~ let c = y;
|
|
|
|
|
|
|
error: using a reference to `Cow` is not recommended
|
|
--> tests/ui/ptr_arg.rs:112:25
|
|
|
|
|
LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
|
|
| ^^^^^^^^^^^ help: change this to: `&[i32]`
|
|
|
|
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:142:66
|
|
|
|
|
LL | fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec<u32>, _s: &String) {}
|
|
| ^^^^^^^ help: change this to: `&str`
|
|
|
|
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:172:21
|
|
|
|
|
LL | fn foo_vec(vec: &Vec<u8>) {
|
|
| ^^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn foo_vec(vec: &[u8]) {
|
|
LL |
|
|
LL ~ let _ = vec.to_owned().pop();
|
|
LL ~ let _ = vec.to_owned().clone();
|
|
|
|
|
|
|
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:178:23
|
|
|
|
|
LL | fn foo_path(path: &PathBuf) {
|
|
| ^^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn foo_path(path: &Path) {
|
|
LL |
|
|
LL ~ let _ = path.to_path_buf().pop();
|
|
LL ~ let _ = path.to_path_buf().clone();
|
|
|
|
|
|
|
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:184:21
|
|
|
|
|
LL | fn foo_str(str: &PathBuf) {
|
|
| ^^^^^^^^
|
|
|
|
|
help: change this to
|
|
|
|
|
LL ~ fn foo_str(str: &Path) {
|
|
LL |
|
|
LL ~ let _ = str.to_path_buf().pop();
|
|
LL ~ let _ = str.to_path_buf().clone();
|
|
|
|
|
|
|
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:191:29
|
|
|
|
|
LL | fn mut_vec_slice_methods(v: &mut Vec<u32>) {
|
|
| ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
|
|
|
|
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:254:17
|
|
|
|
|
LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
|
|
| ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
|
|
|
|
error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:254:35
|
|
|
|
|
LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
|
|
| ^^^^^^^^^^^ help: change this to: `&mut str`
|
|
|
|
error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do
|
|
--> tests/ui/ptr_arg.rs:254:51
|
|
|
|
|
LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
|
|
| ^^^^^^^^^^^^ help: change this to: `&mut Path`
|
|
|
|
error: using a reference to `Cow` is not recommended
|
|
--> tests/ui/ptr_arg.rs:280:39
|
|
|
|
|
LL | fn cow_elided_lifetime<'a>(input: &'a Cow<str>) -> &'a str {
|
|
| ^^^^^^^^^^^^ help: change this to: `&str`
|
|
|
|
error: using a reference to `Cow` is not recommended
|
|
--> tests/ui/ptr_arg.rs:286:36
|
|
|
|
|
LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str {
|
|
| ^^^^^^^^^^^^^^^^ help: change this to: `&str`
|
|
|
|
error: using a reference to `Cow` is not recommended
|
|
--> tests/ui/ptr_arg.rs:290:40
|
|
|
|
|
LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
|
|
| ^^^^^^^^^^^^^^^^ help: change this to: `&str`
|
|
|
|
error: aborting due to 24 previous errors
|
|
|