Skip to content

Commit 07b37cf

Browse files
Use TypeVisitor::BreakTy in ProhibitOpaqueTypes
1 parent 65cdc21 commit 07b37cf

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

compiler/rustc_lint/src/types.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1131,18 +1131,14 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
11311131
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
11321132
struct ProhibitOpaqueTypes<'a, 'tcx> {
11331133
cx: &'a LateContext<'tcx>,
1134-
ty: Option<Ty<'tcx>>,
11351134
};
11361135

11371136
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
1138-
type BreakTy = ();
1137+
type BreakTy = Ty<'tcx>;
11391138

11401139
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
11411140
match ty.kind() {
1142-
ty::Opaque(..) => {
1143-
self.ty = Some(ty);
1144-
ControlFlow::BREAK
1145-
}
1141+
ty::Opaque(..) => ControlFlow::Break(ty),
11461142
// Consider opaque types within projections FFI-safe if they do not normalize
11471143
// to more opaque types.
11481144
ty::Projection(..) => {
@@ -1161,9 +1157,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
11611157
}
11621158
}
11631159

1164-
let mut visitor = ProhibitOpaqueTypes { cx: self.cx, ty: None };
1165-
ty.visit_with(&mut visitor);
1166-
if let Some(ty) = visitor.ty {
1160+
if let Some(ty) = ty.visit_with(&mut ProhibitOpaqueTypes { cx: self.cx }).break_value() {
11671161
self.emit_ffi_unsafe_type_lint(ty, sp, "opaque types have no C equivalent", None);
11681162
true
11691163
} else {

0 commit comments

Comments
 (0)