Skip to content

Commit de66639

Browse files
Revert "Add recursion limit to FFI safety lint"
This reverts commit 7160447.
1 parent 702987f commit de66639

File tree

5 files changed

+18
-50
lines changed

5 files changed

+18
-50
lines changed

compiler/rustc_lint/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,6 @@ lint_improper_ctypes_opaque = opaque types have no C equivalent
395395
lint_improper_ctypes_pat_help = consider using the base type instead
396396
397397
lint_improper_ctypes_pat_reason = pattern types have no C equivalent
398-
399-
lint_improper_ctypes_recursion_limit_reached = type is infinitely recursive
400398
lint_improper_ctypes_slice_help = consider using a raw pointer instead
401399
402400
lint_improper_ctypes_slice_reason = slices have no C equivalent

compiler/rustc_lint/src/types.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,6 @@ struct CTypesVisitorState<'tcx> {
592592
/// The original type being checked, before we recursed
593593
/// to any other types it contains.
594594
base_ty: Ty<'tcx>,
595-
/// Number of times we recursed while checking the type
596-
recursion_depth: usize,
597595
}
598596

599597
enum FfiResult<'tcx> {
@@ -899,23 +897,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
899897

900898
// Protect against infinite recursion, for example
901899
// `struct S(*mut S);`.
900+
// FIXME: A recursion limit is necessary as well, for irregular
901+
// recursive types.
902902
if !acc.cache.insert(ty) {
903903
return FfiSafe;
904904
}
905905

906-
// Additional recursion check for more complex types like
907-
// `struct A<T> { v: *const A<A<T>>, ... }` for which the
908-
// cache check above won't be enough (fixes #130310)
909-
if !tcx.recursion_limit().value_within_limit(acc.recursion_depth) {
910-
return FfiUnsafe {
911-
ty: acc.base_ty,
912-
reason: fluent::lint_improper_ctypes_recursion_limit_reached,
913-
help: None,
914-
};
915-
}
916-
917-
acc.recursion_depth += 1;
918-
919906
match *ty.kind() {
920907
ty::Adt(def, args) => {
921908
if let Some(boxed) = ty.boxed_ty()
@@ -1261,8 +1248,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
12611248
return;
12621249
}
12631250

1264-
let mut acc =
1265-
CTypesVisitorState { cache: FxHashSet::default(), base_ty: ty, recursion_depth: 0 };
1251+
let mut acc = CTypesVisitorState { cache: FxHashSet::default(), base_ty: ty };
12661252
match self.check_type_for_ffi(&mut acc, ty) {
12671253
FfiResult::FfiSafe => {}
12681254
FfiResult::FfiPhantom(ty) => {

tests/crashes/130310.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ known-bug: rust-lang/rust#130310
2+
3+
use std::marker::PhantomData;
4+
5+
#[repr(C)]
6+
struct A<T> {
7+
a: *const A<A<T>>,
8+
p: PhantomData<T>,
9+
}
10+
11+
extern "C" {
12+
fn f(a: *const A<()>);
13+
}
14+
15+
fn main() {}

tests/ui/lint/improper-types-stack-overflow-130310.rs

-20
This file was deleted.

tests/ui/lint/improper-types-stack-overflow-130310.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)