@@ -7,13 +7,12 @@ use clippy_utils::ty::{
7
7
use clippy_utils:: { get_trait_def_id, is_self, paths} ;
8
8
use if_chain:: if_chain;
9
9
use rustc_ast:: ast:: Attribute ;
10
- use rustc_data_structures:: fx:: FxHashSet ;
11
10
use rustc_errors:: { Applicability , Diagnostic } ;
12
11
use rustc_hir:: intravisit:: FnKind ;
13
12
use rustc_hir:: {
14
13
BindingAnnotation , Body , FnDecl , GenericArg , HirId , Impl , ItemKind , Mutability , Node , PatKind , QPath , TyKind ,
15
14
} ;
16
- use rustc_hir:: { HirIdMap , HirIdSet , LangItem } ;
15
+ use rustc_hir:: { HirIdSet , LangItem } ;
17
16
use rustc_hir_typeck:: expr_use_visitor as euv;
18
17
use rustc_infer:: infer:: TyCtxtInferExt ;
19
18
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -138,8 +137,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
138
137
// function body.
139
138
let MovedVariablesCtxt {
140
139
moved_vars,
141
- spans_need_deref,
142
- ..
143
140
} = {
144
141
let mut ctx = MovedVariablesCtxt :: default ( ) ;
145
142
let infcx = cx. tcx . infer_ctxt ( ) . build ( ) ;
@@ -211,7 +208,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
211
208
}
212
209
}
213
210
214
- let deref_span = spans_need_deref. get( & canonical_id) ;
215
211
if_chain! {
216
212
if is_type_diagnostic_item( cx, ty, sym:: Vec ) ;
217
213
if let Some ( clone_spans) =
@@ -247,7 +243,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
247
243
}
248
244
249
245
// cannot be destructured, no need for `*` suggestion
250
- assert!( deref_span. is_none( ) ) ;
251
246
return ;
252
247
}
253
248
}
@@ -275,23 +270,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
275
270
) ;
276
271
}
277
272
278
- assert!( deref_span. is_none( ) ) ;
279
273
return ;
280
274
}
281
275
}
282
276
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
+
295
279
multispan_sugg( diag, "consider taking a reference instead" , spans) ;
296
280
} ;
297
281
@@ -320,9 +304,6 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
320
304
#[ derive( Default ) ]
321
305
struct MovedVariablesCtxt {
322
306
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 > > ,
326
307
}
327
308
328
309
impl MovedVariablesCtxt {
0 commit comments