@@ -221,7 +221,7 @@ struct DerefDelegate<'a, 'tcx> {
221
221
222
222
impl DerefDelegate < ' _ , ' tcx > {
223
223
pub fn finish ( & mut self ) -> String {
224
- let end_span = Span :: new ( self . next_pos , self . closure_span . hi ( ) , self . closure_span . ctxt ( ) ) ;
224
+ let end_span = Span :: new ( self . next_pos , self . closure_span . hi ( ) , self . closure_span . ctxt ( ) , None ) ;
225
225
let end_snip = snippet_with_applicability ( self . cx , end_span, ".." , & mut self . applicability ) ;
226
226
format ! ( "{}{}" , self . suggestion_start, end_snip)
227
227
}
@@ -255,16 +255,22 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
255
255
let map = self . cx . tcx . hir ( ) ;
256
256
let ident_str = map. name ( id) . to_string ( ) ;
257
257
let span = map. span ( cmt. hir_id ) ;
258
- let start_span = Span :: new ( self . next_pos , span. lo ( ) , span. ctxt ( ) ) ;
258
+ let start_span = Span :: new ( self . next_pos , span. lo ( ) , span. ctxt ( ) , None ) ;
259
259
let mut start_snip = snippet_with_applicability ( self . cx , start_span, ".." , & mut self . applicability ) ;
260
260
261
261
if cmt. place . projections . is_empty ( ) {
262
262
// handle item without any projection, that needs an explicit borrowing
263
263
// i.e.: suggest `&x` instead of `x`
264
264
self . suggestion_start . push_str ( & format ! ( "{}&{}" , start_snip, ident_str) ) ;
265
265
} else {
266
- // cases where a parent call is using the item
266
+ // cases where a parent `Call` or `MethodCall` is using the item
267
267
// i.e.: suggest `.contains(&x)` for `.find(|x| [1, 2, 3].contains(x)).is_none()`
268
+ //
269
+ // Note about method calls:
270
+ // - compiler automatically dereference references if the target type is a reference (works also for
271
+ // function call)
272
+ // - `self` arguments in the case of `x.is_something()` are also automatically (de)referenced, and
273
+ // no projection should be suggested
268
274
if let Some ( parent_expr) = get_parent_expr_for_hir ( self . cx , cmt. hir_id ) {
269
275
if let ExprKind :: Call ( _, call_args) | ExprKind :: MethodCall ( _, _, call_args, _) = parent_expr. kind {
270
276
let expr = self . cx . tcx . hir ( ) . expect_expr ( cmt. hir_id ) ;
@@ -316,7 +322,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
316
322
// so the span is set-up again to get more code, using `span.hi()` (i.e.: `foo[x]`)
317
323
// instead of `span.lo()` (i.e.: `foo`)
318
324
ProjectionKind :: Index => {
319
- let start_span = Span :: new ( self . next_pos , span. hi ( ) , span. ctxt ( ) ) ;
325
+ let start_span = Span :: new ( self . next_pos , span. hi ( ) , span. ctxt ( ) , None ) ;
320
326
start_snip = snippet_with_applicability ( self . cx , start_span, ".." , & mut self . applicability ) ;
321
327
replacement_str. clear ( ) ;
322
328
projections_handled = true ;
0 commit comments