Use TypeVisitor::BreakTy
in ProhibitOpaqueTypes
This commit is contained in:
parent
65cdc21f06
commit
07b37cf791
1 changed files with 3 additions and 9 deletions
|
@ -1131,18 +1131,14 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
|
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
|
||||||
struct ProhibitOpaqueTypes<'a, 'tcx> {
|
struct ProhibitOpaqueTypes<'a, 'tcx> {
|
||||||
cx: &'a LateContext<'tcx>,
|
cx: &'a LateContext<'tcx>,
|
||||||
ty: Option<Ty<'tcx>>,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
|
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
|
||||||
type BreakTy = ();
|
type BreakTy = Ty<'tcx>;
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Opaque(..) => {
|
ty::Opaque(..) => ControlFlow::Break(ty),
|
||||||
self.ty = Some(ty);
|
|
||||||
ControlFlow::BREAK
|
|
||||||
}
|
|
||||||
// Consider opaque types within projections FFI-safe if they do not normalize
|
// Consider opaque types within projections FFI-safe if they do not normalize
|
||||||
// to more opaque types.
|
// to more opaque types.
|
||||||
ty::Projection(..) => {
|
ty::Projection(..) => {
|
||||||
|
@ -1161,9 +1157,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut visitor = ProhibitOpaqueTypes { cx: self.cx, ty: None };
|
if let Some(ty) = ty.visit_with(&mut ProhibitOpaqueTypes { cx: self.cx }).break_value() {
|
||||||
ty.visit_with(&mut visitor);
|
|
||||||
if let Some(ty) = visitor.ty {
|
|
||||||
self.emit_ffi_unsafe_type_lint(ty, sp, "opaque types have no C equivalent", None);
|
self.emit_ffi_unsafe_type_lint(ty, sp, "opaque types have no C equivalent", None);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue