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 (`&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
  • Loading branch information
dtolnay committed Jun 5, 2021
1 parent 8862629 commit a37b5ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions impl/src/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
_ => {}
}
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion impl/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a37b5ab

Please sign in to comment.