Skip to content

Commit 7ee2081

Browse files
committed
Auto merge of rust-lang#8441 - Jarcho:needless_borrow_temp, r=flip1995
Don't lint `needless_borrow` in method receiver positions fixes rust-lang#8408 fixes rust-lang#8407 fixes rust-lang#8391 fixes rust-lang#8367 fixes rust-lang#8380 This is a temporary fix for `needless_borrow`. The proper fix is included in rust-lang#8355. This should probably be merged into rustc before beta branches on Friday. This issue has been reported six or seven times in the past couple of weeks. changelog: Fix various issues with `needless_borrow` n´. Note to changelog writer: those issues might have been introduced in this release cycle, so this might not matter in the changelog.
2 parents a4cf91b + a135b52 commit 7ee2081

File tree

4 files changed

+8
-26
lines changed

4 files changed

+8
-26
lines changed

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ fn is_auto_reborrow_position(parent: Option<Node<'_>>) -> bool {
528528
fn is_auto_borrow_position(parent: Option<Node<'_>>, child_id: HirId) -> bool {
529529
if let Some(Node::Expr(parent)) = parent {
530530
match parent.kind {
531-
ExprKind::MethodCall(_, [self_arg, ..], _) => self_arg.hir_id == child_id,
531+
// ExprKind::MethodCall(_, [self_arg, ..], _) => self_arg.hir_id == child_id,
532532
ExprKind::Field(..) => true,
533533
ExprKind::Call(f, _) => f.hir_id == child_id,
534534
_ => false,

tests/ui/needless_borrow.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ fn main() {
6464
*x = 5;
6565

6666
let s = String::new();
67-
let _ = s.len();
68-
let _ = s.capacity();
69-
let _ = s.capacity();
67+
// let _ = (&s).len();
68+
// let _ = (&s).capacity();
69+
// let _ = (&&s).capacity();
7070

7171
let x = (1, 2);
7272
let _ = x.0;

tests/ui/needless_borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ fn main() {
6464
*x = 5;
6565

6666
let s = String::new();
67-
let _ = (&s).len();
68-
let _ = (&s).capacity();
69-
let _ = (&&s).capacity();
67+
// let _ = (&s).len();
68+
// let _ = (&s).capacity();
69+
// let _ = (&&s).capacity();
7070

7171
let x = (1, 2);
7272
let _ = (&x).0;

tests/ui/needless_borrow.stderr

+1-19
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,6 @@ error: this expression creates a reference which is immediately dereferenced by
8484
LL | let y: &mut i32 = &mut &mut x;
8585
| ^^^^^^^^^^^ help: change this to: `x`
8686

87-
error: this expression borrows a value the compiler would automatically borrow
88-
--> $DIR/needless_borrow.rs:67:13
89-
|
90-
LL | let _ = (&s).len();
91-
| ^^^^ help: change this to: `s`
92-
93-
error: this expression borrows a value the compiler would automatically borrow
94-
--> $DIR/needless_borrow.rs:68:13
95-
|
96-
LL | let _ = (&s).capacity();
97-
| ^^^^ help: change this to: `s`
98-
99-
error: this expression creates a reference which is immediately dereferenced by the compiler
100-
--> $DIR/needless_borrow.rs:69:13
101-
|
102-
LL | let _ = (&&s).capacity();
103-
| ^^^^^ help: change this to: `s`
104-
10587
error: this expression borrows a value the compiler would automatically borrow
10688
--> $DIR/needless_borrow.rs:72:13
10789
|
@@ -114,5 +96,5 @@ error: this expression borrows a value the compiler would automatically borrow
11496
LL | let _ = unsafe { (&*x).0 };
11597
| ^^^^^ help: change this to: `(*x)`
11698

117-
error: aborting due to 19 previous errors
99+
error: aborting due to 16 previous errors
118100

0 commit comments

Comments
 (0)