needless_pass_by_value: make verbose suggestion
This reduces the number of snippet manipulations, and shows the new reference in context.
This commit is contained in:
parent
35e6057e71
commit
417d4e6210
3 changed files with 136 additions and 29 deletions
|
|
@ -2,7 +2,7 @@ error: this argument is passed by value, but not consumed in the function body
|
|||
--> tests/ui/crashes/needless_pass_by_value-w-late-bound.rs:7:12
|
||||
|
|
||||
LL | fn test(x: Foo<'_>) {}
|
||||
| ^^^^^^^ help: consider taking a reference instead: `&Foo<'_>`
|
||||
| ^^^^^^^
|
||||
|
|
||||
help: or consider marking this type as `Copy`
|
||||
--> tests/ui/crashes/needless_pass_by_value-w-late-bound.rs:5:1
|
||||
|
|
@ -11,6 +11,10 @@ LL | struct Foo<'a>(&'a [(); 100]);
|
|||
| ^^^^^^^^^^^^^^
|
||||
= note: `-D clippy::needless-pass-by-value` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]`
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test(x: &Foo<'_>) {}
|
||||
| +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -17,43 +17,78 @@ error: this argument is passed by value, but not consumed in the function body
|
|||
--> tests/ui/needless_pass_by_value.rs:35:22
|
||||
|
|
||||
LL | fn bar(x: String, y: Wrapper) {
|
||||
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
|
||||
| ^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn bar(x: String, y: &Wrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:44:71
|
||||
|
|
||||
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: V) {
|
||||
| ^ help: consider taking a reference instead: `&V`
|
||||
| ^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: &V) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:58:18
|
||||
|
|
||||
LL | fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `Option<Option<&String>>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_match(x: Option<Option<&String>>, y: Option<Option<String>>) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:73:24
|
||||
|
|
||||
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
|
||||
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
|
||||
| ^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_destructure(x: &Wrapper, y: Wrapper, z: Wrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:73:36
|
||||
|
|
||||
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
|
||||
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
|
||||
| ^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_destructure(x: Wrapper, y: &Wrapper, z: Wrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:92:49
|
||||
|
|
||||
LL | fn test_blanket_ref<T: Foo, S: Serialize>(vals: T, serializable: S) {}
|
||||
| ^ help: consider taking a reference instead: `&T`
|
||||
| ^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_blanket_ref<T: Foo, S: Serialize>(vals: &T, serializable: S) {}
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:95:18
|
||||
|
|
||||
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
|
||||
| ^^^^^^ help: consider taking a reference instead: `&String`
|
||||
| ^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn issue_2114(s: &String, t: String, u: Vec<i32>, v: Vec<i32>) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:95:29
|
||||
|
|
@ -76,7 +111,12 @@ error: this argument is passed by value, but not consumed in the function body
|
|||
--> tests/ui/needless_pass_by_value.rs:95:40
|
||||
|
|
||||
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
|
||||
| ^^^^^^^^ help: consider taking a reference instead: `&Vec<i32>`
|
||||
| ^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn issue_2114(s: String, t: String, u: &Vec<i32>, v: Vec<i32>) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:95:53
|
||||
|
|
@ -105,109 +145,175 @@ error: this argument is passed by value, but not consumed in the function body
|
|||
--> tests/ui/needless_pass_by_value.rs:115:12
|
||||
|
|
||||
LL | t: String,
|
||||
| ^^^^^^ help: consider taking a reference instead: `&String`
|
||||
| ^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | t: &String,
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:125:23
|
||||
|
|
||||
LL | fn baz(&self, uu: U, ss: Self) {}
|
||||
| ^ help: consider taking a reference instead: `&U`
|
||||
| ^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn baz(&self, uu: &U, ss: Self) {}
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:125:30
|
||||
|
|
||||
LL | fn baz(&self, uu: U, ss: Self) {}
|
||||
| ^^^^ help: consider taking a reference instead: `&Self`
|
||||
| ^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn baz(&self, uu: U, ss: &Self) {}
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:149:24
|
||||
|
|
||||
LL | fn bar_copy(x: u32, y: CopyWrapper) {
|
||||
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: or consider marking this type as `Copy`
|
||||
--> tests/ui/needless_pass_by_value.rs:147:1
|
||||
|
|
||||
LL | struct CopyWrapper(u32);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn bar_copy(x: u32, y: &CopyWrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:157:29
|
||||
|
|
||||
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
|
||||
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: or consider marking this type as `Copy`
|
||||
--> tests/ui/needless_pass_by_value.rs:147:1
|
||||
|
|
||||
LL | struct CopyWrapper(u32);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_destructure_copy(x: &CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:157:45
|
||||
|
|
||||
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
|
||||
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: or consider marking this type as `Copy`
|
||||
--> tests/ui/needless_pass_by_value.rs:147:1
|
||||
|
|
||||
LL | struct CopyWrapper(u32);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_destructure_copy(x: CopyWrapper, y: &CopyWrapper, z: CopyWrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:157:61
|
||||
|
|
||||
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
|
||||
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: or consider marking this type as `Copy`
|
||||
--> tests/ui/needless_pass_by_value.rs:147:1
|
||||
|
|
||||
LL | struct CopyWrapper(u32);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: &CopyWrapper) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:173:40
|
||||
|
|
||||
LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {}
|
||||
| ^ help: consider taking a reference instead: `&S`
|
||||
| ^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn some_fun<'b, S: Bar<'b, ()>>(items: &S) {}
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:179:20
|
||||
|
|
||||
LL | fn more_fun(items: impl Club<'static, i32>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn more_fun(items: &impl Club<'static, i32>) {}
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:194:24
|
||||
|
|
||||
LL | fn option_inner_ref(x: Option<String>) {
|
||||
| ^^^^^^^^^^^^^^ help: consider taking a reference instead: `Option<&String>`
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn option_inner_ref(x: Option<&String>) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:204:27
|
||||
|
|
||||
LL | fn non_standard_option(x: non_standard::Option<String>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&non_standard::Option<String>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn non_standard_option(x: &non_standard::Option<String>) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:209:22
|
||||
|
|
||||
LL | fn option_by_name(x: Option<std::option::Option<core::option::Option<non_standard::Option<String>>>>) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `Option<std::option::Option<core::option::Option<&non_standard::Option<String>>>>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn option_by_name(x: Option<std::option::Option<core::option::Option<&non_standard::Option<String>>>>) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:216:18
|
||||
|
|
||||
LL | fn non_option(x: OptStr) {
|
||||
| ^^^^^^ help: consider taking a reference instead: `&OptStr`
|
||||
| ^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn non_option(x: &OptStr) {
|
||||
| +
|
||||
|
||||
error: this argument is passed by value, but not consumed in the function body
|
||||
--> tests/ui/needless_pass_by_value.rs:223:25
|
||||
|
|
||||
LL | fn non_option_either(x: Opt<String>) {
|
||||
| ^^^^^^^^^^^ help: consider taking a reference instead: `&Opt<String>`
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: consider taking a reference instead
|
||||
|
|
||||
LL | fn non_option_either(x: &Opt<String>) {
|
||||
| +
|
||||
|
||||
error: aborting due to 27 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue