@@ -1593,19 +1593,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
15931593 } ] ) ;
15941594 }
15951595 ffir @ FfiResult :: FfiUnsafeWrapper { .. } => {
1596- let mut last_ty = None ;
1597- let mut ffiresult_recursor = Some ( & ffir) ;
1596+ let mut ffiresult_recursor = ControlFlow :: Continue ( & ffir) ;
15981597 let mut cimproper_layers: Vec < ImproperCTypesLayer < ' tcx > > = vec ! [ ] ;
15991598
16001599 // this whole while block converts the arbitrarily-deep
1601- // FfiResult stack to a ImproperCTypesLayer Vec
1602- while let Some ( ref ffir_rec) = ffiresult_recursor {
1600+ // FfiResult stack to an ImproperCTypesLayer Vec
1601+ while let ControlFlow :: Continue ( ref ffir_rec) = ffiresult_recursor {
16031602 match ffir_rec {
16041603 FfiResult :: FfiPhantom ( ty) => {
1605- last_ty = Some ( ty. clone ( ) ) ;
1606- let len = cimproper_layers. len ( ) ;
1607- if len > 0 {
1608- cimproper_layers[ len - 1 ] . inner_ty = last_ty. clone ( ) ;
1604+ if let Some ( layer) = cimproper_layers. last_mut ( ) {
1605+ layer. inner_ty = Some ( ty. clone ( ) ) ;
16091606 }
16101607 cimproper_layers. push ( ImproperCTypesLayer {
16111608 ty : ty. clone ( ) ,
@@ -1614,14 +1611,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
16141611 note : fluent:: lint_improper_ctypes_only_phantomdata,
16151612 span_note : None , // filled later
16161613 } ) ;
1617- ffiresult_recursor = None ;
1614+ ffiresult_recursor = ControlFlow :: Break ( ( ) ) ;
16181615 }
16191616 FfiResult :: FfiUnsafe { ty, reason, help }
16201617 | FfiResult :: FfiUnsafeWrapper { ty, reason, help, .. } => {
1621- last_ty = Some ( ty. clone ( ) ) ;
1622- let len = cimproper_layers. len ( ) ;
1623- if len > 0 {
1624- cimproper_layers[ len - 1 ] . inner_ty = last_ty. clone ( ) ;
1618+ if let Some ( layer) = cimproper_layers. last_mut ( ) {
1619+ layer. inner_ty = Some ( ty. clone ( ) ) ;
16251620 }
16261621 cimproper_layers. push ( ImproperCTypesLayer {
16271622 ty : ty. clone ( ) ,
@@ -1632,22 +1627,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
16321627 } ) ;
16331628
16341629 if let FfiResult :: FfiUnsafeWrapper { wrapped, .. } = ffir_rec {
1635- ffiresult_recursor = Some ( wrapped. as_ref ( ) ) ;
1630+ ffiresult_recursor = ControlFlow :: Continue ( wrapped. as_ref ( ) ) ;
16361631 } else {
1637- ffiresult_recursor = None ;
1632+ ffiresult_recursor = ControlFlow :: Break ( ( ) ) ;
16381633 }
16391634 }
16401635 FfiResult :: FfiSafe => {
16411636 bug ! ( "malformed FfiResult stack: it should be unsafe all the way down" )
16421637 }
16431638 } ;
16441639 }
1645- let last_ty = match last_ty {
1646- Some ( last_ty) => last_ty,
1647- None => bug ! (
1648- "This option should definitely have been filled by the loop that just finished"
1649- ) ,
1650- } ;
1640+ // should always have at least one type
1641+ let last_ty = cimproper_layers. last ( ) . unwrap ( ) . ty . clone ( ) ;
16511642 self . emit_ffi_unsafe_type_lint ( last_ty, sp, cimproper_layers) ;
16521643 }
16531644 }
0 commit comments