Skip to content

Commit d4f7e6b

Browse files
Remove dead code in needless_pass_by_value
1 parent 8a1f0cd commit d4f7e6b

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ use clippy_utils::ty::{
77
use clippy_utils::{get_trait_def_id, is_self, paths};
88
use if_chain::if_chain;
99
use rustc_ast::ast::Attribute;
10-
use rustc_data_structures::fx::FxHashSet;
1110
use rustc_errors::{Applicability, Diagnostic};
1211
use rustc_hir::intravisit::FnKind;
1312
use rustc_hir::{
1413
BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Mutability, Node, PatKind, QPath, TyKind,
1514
};
16-
use rustc_hir::{HirIdMap, HirIdSet, LangItem};
15+
use rustc_hir::{HirIdSet, LangItem};
1716
use rustc_hir_typeck::expr_use_visitor as euv;
1817
use rustc_infer::infer::TyCtxtInferExt;
1918
use rustc_lint::{LateContext, LateLintPass};
@@ -138,8 +137,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
138137
// function body.
139138
let MovedVariablesCtxt {
140139
moved_vars,
141-
spans_need_deref,
142-
..
143140
} = {
144141
let mut ctx = MovedVariablesCtxt::default();
145142
let infcx = cx.tcx.infer_ctxt().build();
@@ -211,7 +208,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
211208
}
212209
}
213210

214-
let deref_span = spans_need_deref.get(&canonical_id);
215211
if_chain! {
216212
if is_type_diagnostic_item(cx, ty, sym::Vec);
217213
if let Some(clone_spans) =
@@ -247,7 +243,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
247243
}
248244

249245
// cannot be destructured, no need for `*` suggestion
250-
assert!(deref_span.is_none());
251246
return;
252247
}
253248
}
@@ -275,23 +270,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
275270
);
276271
}
277272

278-
assert!(deref_span.is_none());
279273
return;
280274
}
281275
}
282276

283-
let mut spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))];
284-
285-
// Suggests adding `*` to dereference the added reference.
286-
if let Some(deref_span) = deref_span {
287-
spans.extend(
288-
deref_span
289-
.iter()
290-
.copied()
291-
.map(|span| (span, format!("*{}", snippet(cx, span, "<expr>")))),
292-
);
293-
spans.sort_by_key(|&(span, _)| span);
294-
}
277+
let spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))];
278+
295279
multispan_sugg(diag, "consider taking a reference instead", spans);
296280
};
297281

@@ -320,9 +304,6 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
320304
#[derive(Default)]
321305
struct MovedVariablesCtxt {
322306
moved_vars: HirIdSet,
323-
/// Spans which need to be prefixed with `*` for dereferencing the
324-
/// suggested additional reference.
325-
spans_need_deref: HirIdMap<FxHashSet<Span>>,
326307
}
327308

328309
impl MovedVariablesCtxt {

0 commit comments

Comments
 (0)