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
This commit is contained in:
bors 2020-12-13 16:59:02 +00:00
commit 6b2b3576eb
3 changed files with 8 additions and 5 deletions

View File

@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
return; return;
} }
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind { if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind {
if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind() { if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty(inner).kind() {
for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) { for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) {
if let [Adjustment { if let [Adjustment {
kind: Adjust::Deref(_), .. kind: Adjust::Deref(_), ..
@ -62,8 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
cx, cx,
NEEDLESS_BORROW, NEEDLESS_BORROW,
e.span, e.span,
"this expression borrows a reference that is immediately dereferenced \ &format!(
"this expression borrows a reference (`&{}`) that is immediately dereferenced \
by the compiler", by the compiler",
ty
),
|diag| { |diag| {
if let Some(snippet) = snippet_opt(cx, inner.span) { if let Some(snippet) = snippet_opt(cx, inner.span) {
diag.span_suggestion( diag.span_suggestion(

View File

@ -12,7 +12,7 @@ error: redundant closure found
LL | meta(|a| foo(a)); LL | meta(|a| foo(a));
| ^^^^^^^^^^ help: remove closure as shown: `foo` | ^^^^^^^^^^ help: remove closure as shown: `foo`
error: this expression borrows a reference that is immediately dereferenced by the compiler error: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
--> $DIR/eta.rs:24:21 --> $DIR/eta.rs:24:21
| |
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted

View File

@ -1,4 +1,4 @@
error: this expression borrows a reference that is immediately dereferenced by the compiler error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:14:15 --> $DIR/needless_borrow.rs:14:15
| |
LL | let c = x(&&a); LL | let c = x(&&a);
@ -12,7 +12,7 @@ error: this pattern creates a reference to a reference
LL | if let Some(ref cake) = Some(&5) {} LL | if let Some(ref cake) = Some(&5) {}
| ^^^^^^^^ help: change this to: `cake` | ^^^^^^^^ help: change this to: `cake`
error: this expression borrows a reference that is immediately dereferenced by the compiler error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:28:15 --> $DIR/needless_borrow.rs:28:15
| |
LL | 46 => &&a, LL | 46 => &&a,