@@ -289,23 +289,24 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
289
289
let ( position, adjustments) = walk_parents ( cx, & mut self . possible_borrowers , expr, & self . msrv ) ;
290
290
match kind {
291
291
RefOp :: Deref => {
292
+ let sub_ty = typeck. expr_ty ( sub_expr) ;
292
293
if let Position :: FieldAccess {
293
294
name,
294
295
of_union : false ,
295
296
} = position
296
- && !ty_contains_field ( typeck . expr_ty ( sub_expr ) , name)
297
+ && !ty_contains_field ( sub_ty , name)
297
298
{
298
299
self . state = Some ( (
299
300
State :: ExplicitDerefField { name } ,
300
301
StateData { span : expr. span , hir_id : expr. hir_id , position } ,
301
302
) ) ;
302
- } else if position. is_deref_stable ( ) {
303
+ } else if position. is_deref_stable ( ) && sub_ty . is_ref ( ) {
303
304
self . state = Some ( (
304
305
State :: ExplicitDeref { mutability : None } ,
305
306
StateData { span : expr. span , hir_id : expr. hir_id , position } ,
306
307
) ) ;
307
308
}
308
- }
309
+ } ,
309
310
RefOp :: Method ( target_mut)
310
311
if !is_lint_allowed ( cx, EXPLICIT_DEREF_METHODS , expr. hir_id )
311
312
&& position. lint_explicit_deref ( ) =>
@@ -320,7 +321,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
320
321
StateData {
321
322
span : expr. span ,
322
323
hir_id : expr. hir_id ,
323
- position
324
+ position,
324
325
} ,
325
326
) ) ;
326
327
} ,
@@ -394,7 +395,11 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
394
395
msg,
395
396
snip_expr,
396
397
} ) ,
397
- StateData { span : expr. span , hir_id : expr. hir_id , position } ,
398
+ StateData {
399
+ span : expr. span ,
400
+ hir_id : expr. hir_id ,
401
+ position,
402
+ } ,
398
403
) ) ;
399
404
} else if position. is_deref_stable ( )
400
405
// Auto-deref doesn't combine with other adjustments
@@ -406,7 +411,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
406
411
StateData {
407
412
span : expr. span ,
408
413
hir_id : expr. hir_id ,
409
- position
414
+ position,
410
415
} ,
411
416
) ) ;
412
417
}
0 commit comments