@@ -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 } ;
@@ -136,11 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
136
135
137
136
// Collect moved variables and spans which will need dereferencings from the
138
137
// function body.
139
- let MovedVariablesCtxt {
140
- moved_vars,
141
- spans_need_deref,
142
- ..
143
- } = {
138
+ let MovedVariablesCtxt { moved_vars } = {
144
139
let mut ctx = MovedVariablesCtxt :: default ( ) ;
145
140
let infcx = cx. tcx . infer_ctxt ( ) . build ( ) ;
146
141
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 {
211
206
}
212
207
}
213
208
214
- let deref_span = spans_need_deref. get( & canonical_id) ;
215
209
if_chain! {
216
210
if is_type_diagnostic_item( cx, ty, sym:: Vec ) ;
217
211
if let Some ( clone_spans) =
@@ -247,7 +241,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
247
241
}
248
242
249
243
// cannot be destructured, no need for `*` suggestion
250
- assert!( deref_span. is_none( ) ) ;
251
244
return ;
252
245
}
253
246
}
@@ -275,23 +268,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
275
268
) ;
276
269
}
277
270
278
- assert!( deref_span. is_none( ) ) ;
279
271
return ;
280
272
}
281
273
}
282
274
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
+
295
277
multispan_sugg( diag, "consider taking a reference instead" , spans) ;
296
278
} ;
297
279
@@ -320,9 +302,6 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
320
302
#[ derive( Default ) ]
321
303
struct MovedVariablesCtxt {
322
304
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
305
}
327
306
328
307
impl MovedVariablesCtxt {
0 commit comments