Skip to content

Commit c3ef220

Browse files
committed
Rebase and update ui test
1 parent ee2f547 commit c3ef220

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

clippy_lints/src/needless_borrowed_ref.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
//! This lint is **warn** by default
44
55
use rustc::lint::*;
6-
use rustc::hir::{MutImmutable, Pat, PatKind, BindByRef};
7-
use rustc::ty;
6+
use rustc::hir::{MutImmutable, Pat, PatKind, BindingAnnotation};
87
use utils::{span_lint_and_then, in_macro, snippet};
98

109
/// **What it does:** Checks for useless borrowed references.
@@ -63,16 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
6362
}
6463

6564
if_let_chain! {[
66-
// Pat is a pattern whose node
67-
// is a binding which "involves" an immutable reference...
68-
let PatKind::Binding(BindingAnnotation::Ref, ..) = pat.node,
69-
// Pattern's type is a reference. Get the type and mutability of referenced value (tam: TypeAndMut).
70-
let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty,
7165
// Only lint immutable refs, because `&mut ref T` may be useful.
7266
let PatKind::Ref(ref sub_pat, MutImmutable) = pat.node,
7367

7468
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
75-
let PatKind::Binding(BindByRef(MutImmutable), _, spanned_name, ..) = sub_pat.node,
69+
let PatKind::Binding(BindingAnnotation::Ref, _, spanned_name, ..) = sub_pat.node,
7670
], {
7771
span_lint_and_then(cx, NEEDLESS_BORROWED_REFERENCE, pat.span,
7872
"this pattern takes a reference on something that is being de-referenced",

tests/ui/needless_borrow.stderr

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@ error: this expression borrows a reference that is immediately dereferenced by t
1818
27 | 46 => &&a,
1919
| ^^^
2020

21+
error: this pattern takes a reference on something that is being de-referenced
22+
--> $DIR/needless_borrow.rs:49:34
23+
|
24+
49 | let _ = v.iter_mut().filter(|&ref a| a.is_empty());
25+
| ^^^^^^ help: try removing the `&ref` part and just keep: `a`
26+
|
27+
= note: `-D needless-borrowed-reference` implied by `-D warnings`
28+
29+
error: this pattern takes a reference on something that is being de-referenced
30+
--> $DIR/needless_borrow.rs:50:30
31+
|
32+
50 | let _ = v.iter().filter(|&ref a| a.is_empty());
33+
| ^^^^^^ help: try removing the `&ref` part and just keep: `a`
34+
2135
error: this pattern creates a reference to a reference
2236
--> $DIR/needless_borrow.rs:50:31
2337
|
2438
50 | let _ = v.iter().filter(|&ref a| a.is_empty());
2539
| ^^^^^
2640

27-
error: aborting due to 4 previous errors
41+
error: aborting due to 6 previous errors
2842

0 commit comments

Comments
 (0)