Skip to content

Commit c003931

Browse files
CBenoitoli-obk
authored andcommitted
Improve needless_borrowed_ref lint: remove the hand rolled span part.
1 parent fe57fdd commit c003931

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

clippy_lints/src/needless_borrowed_ref.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ use rustc::lint::*;
77
use rustc::hir::{MutImmutable, Pat, PatKind, BindingAnnotation};
88
=======
99
use rustc::hir::{MutImmutable, Pat, PatKind};
10+
<<<<<<< HEAD
1011
>>>>>>> e30bf721... Improve needless_borrowed_ref and add suggestion to it.
1112
use rustc::ty;
13+
=======
14+
>>>>>>> 4ae45c87... Improve needless_borrowed_ref lint: remove the hand rolled span part.
1215
use utils::{span_lint_and_then, in_macro, snippet};
13-
use syntax_pos::{Span, BytePos};
16+
use rustc::hir::BindingMode::BindByRef;
1417

1518
/// **What it does:** Checks for useless borrowed references.
1619
///
@@ -60,14 +63,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
6063
// Only lint immutable refs, because `&mut ref T` may be useful.
6164
let PatKind::Ref(ref sub_pat, MutImmutable) = pat.node,
6265

63-
// Check sub_pat got a 'ref' keyword.
64-
let ty::TyRef(_, _) = cx.tables.pat_ty(sub_pat).sty,
66+
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
67+
let PatKind::Binding(BindByRef(MutImmutable), _, spanned_name, ..) = sub_pat.node,
6568
], {
66-
let part_to_keep = Span{ lo: pat.span.lo + BytePos(5), hi: pat.span.hi, ctxt: pat.span.ctxt };
6769
span_lint_and_then(cx, NEEDLESS_BORROWED_REFERENCE, pat.span,
6870
"this pattern takes a reference on something that is being de-referenced",
6971
|db| {
70-
let hint = snippet(cx, part_to_keep, "..").into_owned();
72+
let hint = snippet(cx, spanned_name.span, "..").into_owned();
7173
db.span_suggestion(pat.span, "try removing the `&ref` part and just keep", hint);
7274
});
7375
}}

0 commit comments

Comments
 (0)