From a37b5ab11f7c133d1bcb24bc67dfe6c037b69a34 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 4 Jun 2021 19:49:11 -0700 Subject: [PATCH] Resolve needless_borrow clippy lints error: this expression borrows a reference (`&ast::Field`) that is immediately dereferenced by the compiler --> impl/src/prop.rs:68:25 | 68 | return Some(&field); | ^^^^^^ help: change this to: `field` | = note: `-D clippy::needless-borrow` implied by `-D 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 (`&ast::Field`) that is immediately dereferenced by the compiler --> impl/src/prop.rs:77:25 | 77 | return Some(&field); | ^^^^^^ help: change this to: `field` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&ast::Field`) that is immediately dereferenced by the compiler --> impl/src/prop.rs:82:70 | 82 | Member::Named(ident) if ident == "source" => return Some(&field), | ^^^^^^ help: change this to: `field` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&ast::Field`) that is immediately dereferenced by the compiler --> impl/src/prop.rs:92:25 | 92 | return Some(&field); | ^^^^^^ help: change this to: `field` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&ast::Field`) that is immediately dereferenced by the compiler --> impl/src/prop.rs:97:25 | 97 | return Some(&field); | ^^^^^^ help: change this to: `field` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression borrows a reference (`&syn::Type`) that is immediately dereferenced by the compiler --> impl/src/valid.rs:191:41 | 191 | if contains_non_static_lifetime(&source_field.ty) { | ^^^^^^^^^^^^^^^^ help: change this to: `source_field.ty` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow --- impl/src/prop.rs | 10 +++++----- impl/src/valid.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/impl/src/prop.rs b/impl/src/prop.rs index e011848..059b74b 100644 --- a/impl/src/prop.rs +++ b/impl/src/prop.rs @@ -65,7 +65,7 @@ impl Field<'_> { fn from_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { for field in fields { if field.attrs.from.is_some() { - return Some(&field); + return Some(field); } } None @@ -74,12 +74,12 @@ fn from_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { fn source_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { for field in fields { if field.attrs.from.is_some() || field.attrs.source.is_some() { - return Some(&field); + return Some(field); } } for field in fields { match &field.member { - Member::Named(ident) if ident == "source" => return Some(&field), + Member::Named(ident) if ident == "source" => return Some(field), _ => {} } } @@ -89,12 +89,12 @@ fn source_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { fn backtrace_field<'a, 'b>(fields: &'a [Field<'b>]) -> Option<&'a Field<'b>> { for field in fields { if field.attrs.backtrace.is_some() { - return Some(&field); + return Some(field); } } for field in fields { if field.is_backtrace() { - return Some(&field); + return Some(field); } } None diff --git a/impl/src/valid.rs b/impl/src/valid.rs index 7246d0c..7657265 100644 --- a/impl/src/valid.rs +++ b/impl/src/valid.rs @@ -188,7 +188,7 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> { } } if let Some(source_field) = source_field.or(from_field) { - if contains_non_static_lifetime(&source_field.ty) { + if contains_non_static_lifetime(source_field.ty) { return Err(Error::new_spanned( &source_field.original.ty, "non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static",