Skip to content

Commit 6e03a30

Browse files
committed
Remove fix for rustc bug from needless_borrow
The spans given for derived traits used to not indicate they were from a macro expansion.
1 parent 60826e7 commit 6e03a30

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
18901890
store.register_late_pass(|| box zero_div_zero::ZeroDiv);
18911891
store.register_late_pass(|| box mutex_atomic::Mutex);
18921892
store.register_late_pass(|| box needless_update::NeedlessUpdate);
1893-
store.register_late_pass(|| box needless_borrow::NeedlessBorrow::default());
1893+
store.register_late_pass(|| box needless_borrow::NeedlessBorrow);
18941894
store.register_late_pass(|| box needless_borrowed_ref::NeedlessBorrowedRef);
18951895
store.register_late_pass(|| box no_effect::NoEffect);
18961896
store.register_late_pass(|| box temporary_assignment::TemporaryAssignment);

clippy_lints/src/needless_borrow.rs

+4-24
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
//! This lint is **warn** by default
44
55
use clippy_utils::diagnostics::span_lint_and_then;
6-
use clippy_utils::is_automatically_derived;
76
use clippy_utils::source::snippet_opt;
87
use if_chain::if_chain;
98
use rustc_errors::Applicability;
10-
use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, Item, Mutability, Pat, PatKind};
9+
use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind};
1110
use rustc_lint::{LateContext, LateLintPass};
1211
use rustc_middle::ty;
1312
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
1413
use rustc_session::{declare_tool_lint, impl_lint_pass};
15-
use rustc_span::def_id::LocalDefId;
1614

1715
declare_clippy_lint! {
1816
/// **What it does:** Checks for address of operations (`&`) that are going to
@@ -37,15 +35,13 @@ declare_clippy_lint! {
3735
}
3836

3937
#[derive(Default)]
40-
pub struct NeedlessBorrow {
41-
derived_item: Option<LocalDefId>,
42-
}
38+
pub struct NeedlessBorrow;
4339

4440
impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
4541

4642
impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
4743
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
48-
if e.span.from_expansion() || self.derived_item.is_some() {
44+
if e.span.from_expansion() {
4945
return;
5046
}
5147
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = e.kind {
@@ -86,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
8682
}
8783
}
8884
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
89-
if pat.span.from_expansion() || self.derived_item.is_some() {
85+
if pat.span.from_expansion() {
9086
return;
9187
}
9288
if_chain! {
@@ -116,20 +112,4 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
116112
}
117113
}
118114
}
119-
120-
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
121-
let attrs = cx.tcx.hir().attrs(item.hir_id());
122-
if is_automatically_derived(attrs) {
123-
debug_assert!(self.derived_item.is_none());
124-
self.derived_item = Some(item.def_id);
125-
}
126-
}
127-
128-
fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
129-
if let Some(id) = self.derived_item {
130-
if item.def_id == id {
131-
self.derived_item = None;
132-
}
133-
}
134-
}
135115
}

0 commit comments

Comments
 (0)