@@ -1464,19 +1464,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
14641464 } ] ) ;
14651465 }
14661466 ffir @ FfiResult :: FfiUnsafeWrapper { .. } => {
1467- let mut last_ty = None ;
1468- let mut ffiresult_recursor = Some ( & ffir) ;
1467+ let mut ffiresult_recursor = ControlFlow :: Continue ( & ffir) ;
14691468 let mut cimproper_layers: Vec < ImproperCTypesLayer < ' tcx > > = vec ! [ ] ;
14701469
14711470 // this whole while block converts the arbitrarily-deep
1472- // FfiResult stack to a ImproperCTypesLayer Vec
1473- while let Some ( ref ffir_rec) = ffiresult_recursor {
1471+ // FfiResult stack to an ImproperCTypesLayer Vec
1472+ while let ControlFlow :: Continue ( ref ffir_rec) = ffiresult_recursor {
14741473 match ffir_rec {
14751474 FfiResult :: FfiPhantom ( ty) => {
1476- last_ty = Some ( ty. clone ( ) ) ;
1477- let len = cimproper_layers. len ( ) ;
1478- if len > 0 {
1479- cimproper_layers[ len - 1 ] . inner_ty = last_ty. clone ( ) ;
1475+ if let Some ( layer) = cimproper_layers. last_mut ( ) {
1476+ layer. inner_ty = Some ( ty. clone ( ) ) ;
14801477 }
14811478 cimproper_layers. push ( ImproperCTypesLayer {
14821479 ty : ty. clone ( ) ,
@@ -1485,14 +1482,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
14851482 note : fluent:: lint_improper_ctypes_only_phantomdata,
14861483 span_note : None , // filled later
14871484 } ) ;
1488- ffiresult_recursor = None ;
1485+ ffiresult_recursor = ControlFlow :: Break ( ( ) ) ;
14891486 }
14901487 FfiResult :: FfiUnsafe { ty, reason, help }
14911488 | FfiResult :: FfiUnsafeWrapper { ty, reason, help, .. } => {
1492- last_ty = Some ( ty. clone ( ) ) ;
1493- let len = cimproper_layers. len ( ) ;
1494- if len > 0 {
1495- cimproper_layers[ len - 1 ] . inner_ty = last_ty. clone ( ) ;
1489+ if let Some ( layer) = cimproper_layers. last_mut ( ) {
1490+ layer. inner_ty = Some ( ty. clone ( ) ) ;
14961491 }
14971492 cimproper_layers. push ( ImproperCTypesLayer {
14981493 ty : ty. clone ( ) ,
@@ -1503,22 +1498,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
15031498 } ) ;
15041499
15051500 if let FfiResult :: FfiUnsafeWrapper { wrapped, .. } = ffir_rec {
1506- ffiresult_recursor = Some ( wrapped. as_ref ( ) ) ;
1501+ ffiresult_recursor = ControlFlow :: Continue ( wrapped. as_ref ( ) ) ;
15071502 } else {
1508- ffiresult_recursor = None ;
1503+ ffiresult_recursor = ControlFlow :: Break ( ( ) ) ;
15091504 }
15101505 }
15111506 FfiResult :: FfiSafe => {
15121507 bug ! ( "malformed FfiResult stack: it should be unsafe all the way down" )
15131508 }
15141509 } ;
15151510 }
1516- let last_ty = match last_ty {
1517- Some ( last_ty) => last_ty,
1518- None => bug ! (
1519- "This option should definitely have been filled by the loop that just finished"
1520- ) ,
1521- } ;
1511+ // should always have at least one type
1512+ let last_ty = cimproper_layers. last ( ) . unwrap ( ) . ty . clone ( ) ;
15221513 self . emit_ffi_unsafe_type_lint ( last_ty, sp, cimproper_layers) ;
15231514 }
15241515 }
0 commit comments