Skip to content

Commit

Permalink
Resolve needless_borrow clippy lints
Browse files Browse the repository at this point in the history
    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
  • Loading branch information
dtolnay committed Jun 5, 2021
1 parent 9677954 commit 7b84089
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions serde_derive/src/de.rs
Expand Up @@ -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! {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Self::Value, __E>
where
Expand Down
2 changes: 1 addition & 1 deletion serde_derive/src/internals/check.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion serde_derive/src/ser.rs
Expand Up @@ -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();
Expand Down

0 comments on commit 7b84089

Please sign in to comment.