From 7b840897a9005d86273ca80e4881e34b5c77787c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 4 Jun 2021 20:56:35 -0700 Subject: [PATCH] Resolve needless_borrow clippy lints error: this expression borrows a reference (`&syn::Type`) that is immediately dereferenced by the compiler --> serde_derive/src/internals/check.rs:399:37 | 399 | if let Type::Path(ty) = ungroup(&field.ty) { | ^^^^^^^^^ help: change this to: `field.ty` | note: the lint level is defined here --> serde_derive/src/lib.rs:18:9 | 18 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::needless_borrow)]` implied by `#[deny(clippy::all)]` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler --> serde_derive/src/de.rs:478:52 | 478 | &type_path, params, fields, false, cattrs, &expecting, | ^^^^^^^^^^ help: change this to: `expecting` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler --> serde_derive/src/de.rs:564:76 | 564 | let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting)); | ^^^^^^^^^^ help: change this to: `expecting` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler --> serde_derive/src/de.rs:925:51 | 925 | &type_path, params, fields, true, cattrs, &expecting, | ^^^^^^^^^^ help: change this to: `expecting` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler --> serde_derive/src/de.rs:1066:76 | 1066 | let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting)); | ^^^^^^^^^^ help: change this to: `expecting` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&proc_macro2::TokenStream`) that is immediately dereferenced by the compiler --> serde_derive/src/de.rs:2288:80 | 2288 | let fallthrough_borrowed_arm = fallthrough_borrowed.as_ref().unwrap_or(&fallthrough_arm); | ^^^^^^^^^^^^^^^^ help: change this to: `fallthrough_arm` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&syn::Member`) that is immediately dereferenced by the compiler --> serde_derive/src/ser.rs:1102:43 | 1102 | get_member(params, field, &member) | ^^^^^^^ help: change this to: `member` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow --- serde_derive/src/de.rs | 10 +++++----- serde_derive/src/internals/check.rs | 2 +- serde_derive/src/ser.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 7b97cd4d2..5d0c00f33 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -475,7 +475,7 @@ fn deserialize_tuple( }; let visit_seq = Stmts(deserialize_seq( - &type_path, params, fields, false, cattrs, &expecting, + &type_path, params, fields, false, cattrs, expecting, )); let visitor_expr = quote! { @@ -561,7 +561,7 @@ fn deserialize_tuple_in_place( None }; - let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting)); + let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, expecting)); let visitor_expr = quote! { __Visitor { @@ -922,7 +922,7 @@ fn deserialize_struct( let expecting = cattrs.expecting().unwrap_or(&expecting); let visit_seq = Stmts(deserialize_seq( - &type_path, params, fields, true, cattrs, &expecting, + &type_path, params, fields, true, cattrs, expecting, )); let (field_visitor, fields_stmt, visit_map) = if cattrs.has_flatten() { @@ -1063,7 +1063,7 @@ fn deserialize_struct_in_place( }; let expecting = cattrs.expecting().unwrap_or(&expecting); - let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting)); + let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, expecting)); let (field_visitor, fields_stmt, visit_map) = deserialize_struct_as_struct_in_place_visitor(params, fields, cattrs); @@ -2285,7 +2285,7 @@ fn deserialize_identifier( }; let visit_borrowed = if fallthrough_borrowed.is_some() || collect_other_fields { - let fallthrough_borrowed_arm = fallthrough_borrowed.as_ref().unwrap_or(&fallthrough_arm); + let fallthrough_borrowed_arm = fallthrough_borrowed.as_ref().unwrap_or(fallthrough_arm); Some(quote! { fn visit_borrowed_str<__E>(self, __value: &'de str) -> _serde::__private::Result where diff --git a/serde_derive/src/internals/check.rs b/serde_derive/src/internals/check.rs index 609181638..0e2484a79 100644 --- a/serde_derive/src/internals/check.rs +++ b/serde_derive/src/internals/check.rs @@ -396,7 +396,7 @@ fn member_message(member: &Member) -> String { } fn allow_transparent(field: &Field, derive: Derive) -> bool { - if let Type::Path(ty) = ungroup(&field.ty) { + if let Type::Path(ty) = ungroup(field.ty) { if let Some(seg) = ty.path.segments.last() { if seg.ident == "PhantomData" { return false; diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index c663c3b02..4f3e5ff08 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -1099,7 +1099,7 @@ fn serialize_struct_visitor( let mut field_expr = if is_enum { quote!(#member) } else { - get_member(params, field, &member) + get_member(params, field, member) }; let key_expr = field.attrs.name().serialize_name();