Skip to content

Commit

Permalink
Don't lint needless_borrow in method receiver positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho authored and flip1995 committed Feb 17, 2022
1 parent 582b696 commit 7fa0c20
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/needless_borrow.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/needless_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 1 addition & 19 deletions src/tools/clippy/tests/ui/needless_borrow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,6 @@ error: this expression creates a reference which is immediately dereferenced by
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
|
Expand All @@ -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

0 comments on commit 7fa0c20

Please sign in to comment.