diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-17 23:01:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-17 23:01:03 +0100 |
| commit | 39c17488fb9daca40f3fa8348409515660c594e4 (patch) | |
| tree | e8710d3ce418b53ef817c313b05d44020e523f14 | |
| parent | e1bf0694820f2a9e62c66512f40aa767258c1a74 (diff) | |
| parent | 7fa0c206272976c3b26b4d1ec6824a3c4d1859a7 (diff) | |
| download | rust-39c17488fb9daca40f3fa8348409515660c594e4.tar.gz rust-39c17488fb9daca40f3fa8348409515660c594e4.zip | |
Rollup merge of #94085 - flip1995:clippy_needless_borrow_temp_fix, r=Manishearth
Clippy: Don't lint `needless_borrow` in method receiver positions r? `@Manishearth` cc `@camsteffen` `@Jarcho` cc rust-lang/rust-clippy#8441 Let's get this fix in before the beta branching tomorrow.
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/dereference.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/needless_borrow.fixed | 6 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/needless_borrow.rs | 6 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/needless_borrow.stderr | 20 |
4 files changed, 8 insertions, 26 deletions
diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 6d0851d804c..fe391198342 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -528,7 +528,7 @@ fn is_auto_reborrow_position(parent: Option<Node<'_>>) -> bool { fn is_auto_borrow_position(parent: Option<Node<'_>>, child_id: HirId) -> bool { if let Some(Node::Expr(parent)) = parent { match parent.kind { - ExprKind::MethodCall(_, [self_arg, ..], _) => self_arg.hir_id == child_id, + // ExprKind::MethodCall(_, [self_arg, ..], _) => self_arg.hir_id == child_id, ExprKind::Field(..) => true, ExprKind::Call(f, _) => f.hir_id == child_id, _ => false, diff --git a/src/tools/clippy/tests/ui/needless_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed index b856f1375d3..efeb5cf5b2b 100644 --- a/src/tools/clippy/tests/ui/needless_borrow.fixed +++ b/src/tools/clippy/tests/ui/needless_borrow.fixed @@ -64,9 +64,9 @@ fn main() { *x = 5; let s = String::new(); - let _ = s.len(); - let _ = s.capacity(); - let _ = s.capacity(); + // let _ = (&s).len(); + // let _ = (&s).capacity(); + // let _ = (&&s).capacity(); let x = (1, 2); let _ = x.0; diff --git a/src/tools/clippy/tests/ui/needless_borrow.rs b/src/tools/clippy/tests/ui/needless_borrow.rs index 0bfe222a3dc..3e416a0eb84 100644 --- a/src/tools/clippy/tests/ui/needless_borrow.rs +++ b/src/tools/clippy/tests/ui/needless_borrow.rs @@ -64,9 +64,9 @@ fn main() { *x = 5; let s = String::new(); - let _ = (&s).len(); - let _ = (&s).capacity(); - let _ = (&&s).capacity(); + // let _ = (&s).len(); + // let _ = (&s).capacity(); + // let _ = (&&s).capacity(); let x = (1, 2); let _ = (&x).0; diff --git a/src/tools/clippy/tests/ui/needless_borrow.stderr b/src/tools/clippy/tests/ui/needless_borrow.stderr index b90e8448db0..05591ce4117 100644 --- a/src/tools/clippy/tests/ui/needless_borrow.stderr +++ b/src/tools/clippy/tests/ui/needless_borrow.stderr @@ -85,24 +85,6 @@ LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:67:13 - | -LL | let _ = (&s).len(); - | ^^^^ help: change this to: `s` - -error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:68:13 - | -LL | let _ = (&s).capacity(); - | ^^^^ help: change this to: `s` - -error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:69:13 - | -LL | let _ = (&&s).capacity(); - | ^^^^^ help: change this to: `s` - -error: this expression borrows a value the compiler would automatically borrow --> $DIR/needless_borrow.rs:72:13 | LL | let _ = (&x).0; @@ -114,5 +96,5 @@ error: this expression borrows a value the compiler would automatically borrow LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` -error: aborting due to 19 previous errors +error: aborting due to 16 previous errors |
