compiler: Tighten up ImproperCTypesLayer recursion · rust-lang/rust@02072fd (original) (raw)

`@@ -1593,19 +1593,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {

`

1593

1593

`}]);

`

1594

1594

`}

`

1595

1595

` ffir @ FfiResult::FfiUnsafeWrapper { .. } => {

`

1596

``

`-

let mut last_ty = None;

`

1597

``

`-

let mut ffiresult_recursor = Some(&ffir);

`

``

1596

`+

let mut ffiresult_recursor = ControlFlow::Continue(&ffir);

`

1598

1597

`let mut cimproper_layers: Vec<ImproperCTypesLayer<'tcx>> = vec![];

`

1599

1598

``

1600

1599

`// 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 {

`

1603

1602

`match ffir_rec {

`

1604

1603

`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());

`

1609

1606

`}

`

1610

1607

` cimproper_layers.push(ImproperCTypesLayer {

`

1611

1608

`ty: ty.clone(),

`

`@@ -1614,14 +1611,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {

`

1614

1611

`note: fluent::lint_improper_ctypes_only_phantomdata,

`

1615

1612

`span_note: None, // filled later

`

1616

1613

`});

`

1617

``

`-

ffiresult_recursor = None;

`

``

1614

`+

ffiresult_recursor = ControlFlow::Break(());

`

1618

1615

`}

`

1619

1616

`FfiResult::FfiUnsafe { ty, reason, help }

`

1620

1617

` | 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());

`

1625

1620

`}

`

1626

1621

` cimproper_layers.push(ImproperCTypesLayer {

`

1627

1622

`ty: ty.clone(),

`

`@@ -1632,22 +1627,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {

`

1632

1627

`});

`

1633

1628

``

1634

1629

`if let FfiResult::FfiUnsafeWrapper { wrapped, .. } = ffir_rec {

`

1635

``

`-

ffiresult_recursor = Some(wrapped.as_ref());

`

``

1630

`+

ffiresult_recursor = ControlFlow::Continue(wrapped.as_ref());

`

1636

1631

`} else {

`

1637

``

`-

ffiresult_recursor = None;

`

``

1632

`+

ffiresult_recursor = ControlFlow::Break(());

`

1638

1633

`}

`

1639

1634

`}

`

1640

1635

`FfiResult::FfiSafe => {

`

1641

1636

`bug!("malformed FfiResult stack: it should be unsafe all the way down")

`

1642

1637

`}

`

1643

1638

`};

`

1644

1639

`}

`

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();

`

1651

1642

`self.emit_ffi_unsafe_type_lint(last_ty, sp, cimproper_layers);

`

1652

1643

`}

`

1653

1644

`}

`