compiler: Tighten up ImproperCTypesLayer recursion
This commit is contained in:
parent
8b6289f6ae
commit
02072fd83a
1 changed files with 12 additions and 21 deletions
|
@ -1593,19 +1593,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
ffir @ FfiResult::FfiUnsafeWrapper { .. } => {
|
ffir @ FfiResult::FfiUnsafeWrapper { .. } => {
|
||||||
let mut last_ty = None;
|
let mut ffiresult_recursor = ControlFlow::Continue(&ffir);
|
||||||
let mut ffiresult_recursor = Some(&ffir);
|
|
||||||
let mut cimproper_layers: Vec<ImproperCTypesLayer<'tcx>> = vec![];
|
let mut cimproper_layers: Vec<ImproperCTypesLayer<'tcx>> = vec![];
|
||||||
|
|
||||||
// this whole while block converts the arbitrarily-deep
|
// this whole while block converts the arbitrarily-deep
|
||||||
// FfiResult stack to a ImproperCTypesLayer Vec
|
// FfiResult stack to an ImproperCTypesLayer Vec
|
||||||
while let Some(ref ffir_rec) = ffiresult_recursor {
|
while let ControlFlow::Continue(ref ffir_rec) = ffiresult_recursor {
|
||||||
match ffir_rec {
|
match ffir_rec {
|
||||||
FfiResult::FfiPhantom(ty) => {
|
FfiResult::FfiPhantom(ty) => {
|
||||||
last_ty = Some(ty.clone());
|
if let Some(layer) = cimproper_layers.last_mut() {
|
||||||
let len = cimproper_layers.len();
|
layer.inner_ty = Some(ty.clone());
|
||||||
if len > 0 {
|
|
||||||
cimproper_layers[len - 1].inner_ty = last_ty.clone();
|
|
||||||
}
|
}
|
||||||
cimproper_layers.push(ImproperCTypesLayer {
|
cimproper_layers.push(ImproperCTypesLayer {
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
|
@ -1614,14 +1611,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
note: fluent::lint_improper_ctypes_only_phantomdata,
|
note: fluent::lint_improper_ctypes_only_phantomdata,
|
||||||
span_note: None, // filled later
|
span_note: None, // filled later
|
||||||
});
|
});
|
||||||
ffiresult_recursor = None;
|
ffiresult_recursor = ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
FfiResult::FfiUnsafe { ty, reason, help }
|
FfiResult::FfiUnsafe { ty, reason, help }
|
||||||
| FfiResult::FfiUnsafeWrapper { ty, reason, help, .. } => {
|
| FfiResult::FfiUnsafeWrapper { ty, reason, help, .. } => {
|
||||||
last_ty = Some(ty.clone());
|
if let Some(layer) = cimproper_layers.last_mut() {
|
||||||
let len = cimproper_layers.len();
|
layer.inner_ty = Some(ty.clone());
|
||||||
if len > 0 {
|
|
||||||
cimproper_layers[len - 1].inner_ty = last_ty.clone();
|
|
||||||
}
|
}
|
||||||
cimproper_layers.push(ImproperCTypesLayer {
|
cimproper_layers.push(ImproperCTypesLayer {
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
|
@ -1632,9 +1627,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if let FfiResult::FfiUnsafeWrapper { wrapped, .. } = ffir_rec {
|
if let FfiResult::FfiUnsafeWrapper { wrapped, .. } = ffir_rec {
|
||||||
ffiresult_recursor = Some(wrapped.as_ref());
|
ffiresult_recursor = ControlFlow::Continue(wrapped.as_ref());
|
||||||
} else {
|
} else {
|
||||||
ffiresult_recursor = None;
|
ffiresult_recursor = ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FfiResult::FfiSafe => {
|
FfiResult::FfiSafe => {
|
||||||
|
@ -1642,12 +1637,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let last_ty = match last_ty {
|
// should always have at least one type
|
||||||
Some(last_ty) => last_ty,
|
let last_ty = cimproper_layers.last().unwrap().ty.clone();
|
||||||
None => bug!(
|
|
||||||
"This option should definitely have been filled by the loop that just finished"
|
|
||||||
),
|
|
||||||
};
|
|
||||||
self.emit_ffi_unsafe_type_lint(last_ty, sp, cimproper_layers);
|
self.emit_ffi_unsafe_type_lint(last_ty, sp, cimproper_layers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue