@@ -289,23 +289,24 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
289289 let ( position, adjustments) = walk_parents ( cx, & mut self . possible_borrowers , expr, & self . msrv ) ;
290290 match kind {
291291 RefOp :: Deref => {
292+ let sub_ty = typeck. expr_ty ( sub_expr) ;
292293 if let Position :: FieldAccess {
293294 name,
294295 of_union : false ,
295296 } = position
296- && !ty_contains_field ( typeck . expr_ty ( sub_expr ) , name)
297+ && !ty_contains_field ( sub_ty , name)
297298 {
298299 self . state = Some ( (
299300 State :: ExplicitDerefField { name } ,
300301 StateData { span : expr. span , hir_id : expr. hir_id , position } ,
301302 ) ) ;
302- } else if position. is_deref_stable ( ) {
303+ } else if position. is_deref_stable ( ) && sub_ty . is_ref ( ) {
303304 self . state = Some ( (
304305 State :: ExplicitDeref { mutability : None } ,
305306 StateData { span : expr. span , hir_id : expr. hir_id , position } ,
306307 ) ) ;
307308 }
308- }
309+ } ,
309310 RefOp :: Method ( target_mut)
310311 if !is_lint_allowed ( cx, EXPLICIT_DEREF_METHODS , expr. hir_id )
311312 && position. lint_explicit_deref ( ) =>
@@ -320,7 +321,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
320321 StateData {
321322 span : expr. span ,
322323 hir_id : expr. hir_id ,
323- position
324+ position,
324325 } ,
325326 ) ) ;
326327 } ,
@@ -394,7 +395,11 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
394395 msg,
395396 snip_expr,
396397 } ) ,
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+ } ,
398403 ) ) ;
399404 } else if position. is_deref_stable ( )
400405 // Auto-deref doesn't combine with other adjustments
@@ -406,7 +411,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
406411 StateData {
407412 span : expr. span ,
408413 hir_id : expr. hir_id ,
409- position
414+ position,
410415 } ,
411416 ) ) ;
412417 }
0 commit comments