Skip to content

Commit 72332b2

Browse files
committed
Auto merge of rust-lang#10944 - GuillaumeGomez:cleanup-needless-pass-by-value, r=xFrednet
Remove dead code in `needless_pass_by_value` The `spans_need_deref` is never used so I removed it alongside all linked code as well. changelog: none
2 parents 5164458 + bcaf655 commit 72332b2

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 4 additions & 25 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};
@@ -136,11 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
136135

137136
// Collect moved variables and spans which will need dereferencings from the
138137
// function body.
139-
let MovedVariablesCtxt {
140-
moved_vars,
141-
spans_need_deref,
142-
..
143-
} = {
138+
let MovedVariablesCtxt { moved_vars } = {
144139
let mut ctx = MovedVariablesCtxt::default();
145140
let infcx = cx.tcx.infer_ctxt().build();
146141
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
@@ -211,7 +206,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
211206
}
212207
}
213208

214-
let deref_span = spans_need_deref.get(&canonical_id);
215209
if_chain! {
216210
if is_type_diagnostic_item(cx, ty, sym::Vec);
217211
if let Some(clone_spans) =
@@ -247,7 +241,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
247241
}
248242

249243
// cannot be destructured, no need for `*` suggestion
250-
assert!(deref_span.is_none());
251244
return;
252245
}
253246
}
@@ -275,23 +268,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
275268
);
276269
}
277270

278-
assert!(deref_span.is_none());
279271
return;
280272
}
281273
}
282274

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-
}
275+
let spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))];
276+
295277
multispan_sugg(diag, "consider taking a reference instead", spans);
296278
};
297279

@@ -320,9 +302,6 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
320302
#[derive(Default)]
321303
struct MovedVariablesCtxt {
322304
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>>,
326305
}
327306

328307
impl MovedVariablesCtxt {

0 commit comments

Comments
 (0)