@@ -795,7 +795,12 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
795795 // The base is a pointer's deref, so we introduce the implicit deref.
796796 AddressBase :: Deref ( reborrow) => {
797797 let place_ty = PlaceTy :: from_ty ( self . ty ( reborrow) ) ;
798- self . project ( place_ty, reborrow, ProjectionElem :: Deref ) ?
798+ self . project ( place_ty, reborrow, ProjectionElem :: Deref ) . unwrap_or_else ( || {
799+ // Insert a deref instead if `reborrow` cannot be dereferenced.
800+ let projection_ty =
801+ place_ty. projection_ty :: < VnIndex > ( self . tcx , ProjectionElem :: Deref ) ;
802+ return ( projection_ty, self . insert_deref ( projection_ty. ty , reborrow) ) ;
803+ } )
799804 }
800805 } ;
801806 for & proj in projection {
@@ -817,9 +822,9 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
817822 if let Some ( Mutability :: Not ) = place_ty. ty . ref_mutability ( )
818823 && projection_ty. ty . is_freeze ( self . tcx , self . typing_env ( ) )
819824 {
820- if let Value :: Address { base, projection, .. } = self . get ( value)
821- && let Some ( value ) = self . dereference_address ( base , projection )
822- {
825+ if let Value :: Address { base, projection, .. } = self . get ( value) {
826+ // Bail out if the address cannot be dereferenced.
827+ let value = self . dereference_address ( base , projection ) ? ;
823828 return Some ( ( projection_ty, value) ) ;
824829 }
825830
0 commit comments