Skip to content

Commit 65cee85

Browse files
committed
Minor cleanup of needless_borrow
1 parent 484a2af commit 65cee85

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

clippy_lints/src/needless_borrow.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
1313
use rustc_middle::lint::in_external_macro;
1414
use rustc_middle::ty;
1515
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
16-
use rustc_session::{declare_tool_lint, impl_lint_pass};
16+
use rustc_session::{declare_lint_pass, declare_tool_lint};
1717

1818
declare_clippy_lint! {
1919
/// **What it does:** Checks for address of operations (`&`) that are going to
@@ -37,8 +37,7 @@ declare_clippy_lint! {
3737
"taking a reference that is going to be automatically dereferenced"
3838
}
3939

40-
pub struct NeedlessBorrow;
41-
impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
40+
declare_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
4241

4342
impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
4443
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
@@ -108,12 +107,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
108107
];
109108

110109
foreach_local_usage(cx, id, search_loc, |e| {
111-
if matches!(
110+
// Check for auto-deref
111+
if !matches!(
112112
cx.typeck_results().expr_adjustments(e),
113113
[Adjustment { kind: Adjust::Deref(_), .. }, Adjustment { kind: Adjust::Deref(_), .. }, ..]
114114
) {
115-
// Compiler inserted deref, nothing to change here
116-
} else {
117115
match get_parent_expr(cx, e) {
118116
Some(&Expr { span, kind: ExprKind::Unary(UnOp::Deref, _), .. })
119117
if span.ctxt() == ctxt => {

0 commit comments

Comments
 (0)