Skip to content

Commit 6b2b357

Browse files
committed
Auto merge of #6449 - matthiaskrgr:needless_borrow_ty, r=ebroto
needless_borrow: print the type in the lint message changelog: needless_borrow: print type in lint message
2 parents 1df2e38 + cd2a62c commit 6b2b357

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

clippy_lints/src/needless_borrow.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
4747
return;
4848
}
4949
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind {
50-
if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind() {
50+
if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty(inner).kind() {
5151
for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) {
5252
if let [Adjustment {
5353
kind: Adjust::Deref(_), ..
@@ -62,8 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
6262
cx,
6363
NEEDLESS_BORROW,
6464
e.span,
65-
"this expression borrows a reference that is immediately dereferenced \
65+
&format!(
66+
"this expression borrows a reference (`&{}`) that is immediately dereferenced \
6667
by the compiler",
68+
ty
69+
),
6770
|diag| {
6871
if let Some(snippet) = snippet_opt(cx, inner.span) {
6972
diag.span_suggestion(

tests/ui/eta.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error: redundant closure found
1212
LL | meta(|a| foo(a));
1313
| ^^^^^^^^^^ help: remove closure as shown: `foo`
1414

15-
error: this expression borrows a reference that is immediately dereferenced by the compiler
15+
error: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
1616
--> $DIR/eta.rs:24:21
1717
|
1818
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted

tests/ui/needless_borrow.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: this expression borrows a reference that is immediately dereferenced by the compiler
1+
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
22
--> $DIR/needless_borrow.rs:14:15
33
|
44
LL | let c = x(&&a);
@@ -12,7 +12,7 @@ error: this pattern creates a reference to a reference
1212
LL | if let Some(ref cake) = Some(&5) {}
1313
| ^^^^^^^^ help: change this to: `cake`
1414

15-
error: this expression borrows a reference that is immediately dereferenced by the compiler
15+
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
1616
--> $DIR/needless_borrow.rs:28:15
1717
|
1818
LL | 46 => &&a,

0 commit comments

Comments
 (0)