about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-06-13 16:41:16 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2023-06-13 17:08:51 +0200
commitbcaf655b70671275ca07b7f5c924f27125ee8c0b (patch)
tree9096d47d8b5915492e79a6c85566e298ccb7fd37
parent8a1f0cd765a625d469ee0f874f83a34518334488 (diff)
downloadrust-bcaf655b70671275ca07b7f5c924f27125ee8c0b.tar.gz
rust-bcaf655b70671275ca07b7f5c924f27125ee8c0b.zip
Remove dead code in `needless_pass_by_value`
-rw-r--r--clippy_lints/src/needless_pass_by_value.rs29
1 files changed, 4 insertions, 25 deletions
diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs
index 7d53fe65658..3b118239a21 100644
--- a/clippy_lints/src/needless_pass_by_value.rs
+++ b/clippy_lints/src/needless_pass_by_value.rs
@@ -7,13 +7,12 @@ use clippy_utils::ty::{
 use clippy_utils::{get_trait_def_id, is_self, paths};
 use if_chain::if_chain;
 use rustc_ast::ast::Attribute;
-use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{Applicability, Diagnostic};
 use rustc_hir::intravisit::FnKind;
 use rustc_hir::{
     BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Mutability, Node, PatKind, QPath, TyKind,
 };
-use rustc_hir::{HirIdMap, HirIdSet, LangItem};
+use rustc_hir::{HirIdSet, LangItem};
 use rustc_hir_typeck::expr_use_visitor as euv;
 use rustc_infer::infer::TyCtxtInferExt;
 use rustc_lint::{LateContext, LateLintPass};
@@ -136,11 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
 
         // Collect moved variables and spans which will need dereferencings from the
         // function body.
-        let MovedVariablesCtxt {
-            moved_vars,
-            spans_need_deref,
-            ..
-        } = {
+        let MovedVariablesCtxt { moved_vars } = {
             let mut ctx = MovedVariablesCtxt::default();
             let infcx = cx.tcx.infer_ctxt().build();
             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 {
                             }
                         }
 
-                        let deref_span = spans_need_deref.get(&canonical_id);
                         if_chain! {
                             if is_type_diagnostic_item(cx, ty, sym::Vec);
                             if let Some(clone_spans) =
@@ -247,7 +241,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
                                 }
 
                                 // cannot be destructured, no need for `*` suggestion
-                                assert!(deref_span.is_none());
                                 return;
                             }
                         }
@@ -275,23 +268,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
                                     );
                                 }
 
-                                assert!(deref_span.is_none());
                                 return;
                             }
                         }
 
-                        let mut spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))];
-
-                        // Suggests adding `*` to dereference the added reference.
-                        if let Some(deref_span) = deref_span {
-                            spans.extend(
-                                deref_span
-                                    .iter()
-                                    .copied()
-                                    .map(|span| (span, format!("*{}", snippet(cx, span, "<expr>")))),
-                            );
-                            spans.sort_by_key(|&(span, _)| span);
-                        }
+                        let spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))];
+
                         multispan_sugg(diag, "consider taking a reference instead", spans);
                     };
 
@@ -320,9 +302,6 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
 #[derive(Default)]
 struct MovedVariablesCtxt {
     moved_vars: HirIdSet,
-    /// Spans which need to be prefixed with `*` for dereferencing the
-    /// suggested additional reference.
-    spans_need_deref: HirIdMap<FxHashSet<Span>>,
 }
 
 impl MovedVariablesCtxt {