@@ -221,7 +221,7 @@ struct DerefDelegate<'a, 'tcx> {
221221
222222impl DerefDelegate < ' _ , ' tcx > {
223223 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 ) ;
225225 let end_snip = snippet_with_applicability ( self . cx , end_span, ".." , & mut self . applicability ) ;
226226 format ! ( "{}{}" , self . suggestion_start, end_snip)
227227 }
@@ -255,16 +255,22 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
255255 let map = self . cx . tcx . hir ( ) ;
256256 let ident_str = map. name ( id) . to_string ( ) ;
257257 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 ) ;
259259 let mut start_snip = snippet_with_applicability ( self . cx , start_span, ".." , & mut self . applicability ) ;
260260
261261 if cmt. place . projections . is_empty ( ) {
262262 // handle item without any projection, that needs an explicit borrowing
263263 // i.e.: suggest `&x` instead of `x`
264264 self . suggestion_start . push_str ( & format ! ( "{}&{}" , start_snip, ident_str) ) ;
265265 } else {
266- // cases where a parent call is using the item
266+ // cases where a parent `Call` or `MethodCall` is using the item
267267 // 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
268274 if let Some ( parent_expr) = get_parent_expr_for_hir ( self . cx , cmt. hir_id ) {
269275 if let ExprKind :: Call ( _, call_args) | ExprKind :: MethodCall ( _, _, call_args, _) = parent_expr. kind {
270276 let expr = self . cx . tcx . hir ( ) . expect_expr ( cmt. hir_id ) ;
@@ -316,7 +322,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
316322 // so the span is set-up again to get more code, using `span.hi()` (i.e.: `foo[x]`)
317323 // instead of `span.lo()` (i.e.: `foo`)
318324 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 ) ;
320326 start_snip = snippet_with_applicability ( self . cx , start_span, ".." , & mut self . applicability ) ;
321327 replacement_str. clear ( ) ;
322328 projections_handled = true ;
0 commit comments