Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bindings fail to compile with "recursive type .. has infinte size" and "cycle detected when computing drop-check constraints" #1913

Open
boydjohnson opened this issue Nov 4, 2020 · 1 comment

Comments

@boydjohnson
Copy link

C++ header

template <class a> struct b : a { typename b::c d; };

bindgen command

bindgen test-case-3.hpp -- -x c++

Produced bindings

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct b<a> {
    pub _base: a,
    pub d: b<a>,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<a>>,
}

rustc --crate-type lib bindings.rs produces

error[E0072]: recursive type `b` has infinite size
 --> bindings.rs:5:1
  |
5 | pub struct b<a> {
  | ^^^^^^^^^^^^^^^ recursive type has infinite size
6 |     pub _base: a,
7 |     pub d: b<a>,
  |            ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `b` representable
  |
7 |     pub d: Box<b<a>>,
  |            ^^^^    ^

error[E0391]: cycle detected when computing drop-check constraints for `b`
 --> bindings.rs:5:1
  |
5 | pub struct b<a> {
@adetaylor
Copy link
Contributor

The pre-existing test case issue-544-stylo-creduce-2 hits this same bug as well, when we come to support dependent qualified types as in #1924. Here's a minimized version of that test case which strips out the dependent qualified types stuff and demonstrates the same thing:
master...adetaylor:recursive-type-test

adetaylor added a commit to adetaylor/rust-bindgen that referenced this issue Apr 23, 2021
When dependent qualified types are supported, this runs into
a different bug, rust-lang#1913, where we generate an infinitely deep
structure. The reduced template here doesn't really make any
sense and wouldn't be encountered in the wild quite like this.

Previously we generated opaque types for this case, so we didn't
run into that bug. We now generate higher-fidelity types and therefore
hit the problem.

I can't see any way to salvage the fundamentals of this test case
without the recursive problem, so I propose to remove it.
adetaylor added a commit to adetaylor/rust-bindgen that referenced this issue Apr 23, 2021
When dependent qualified types are supported, this runs into
a different bug, rust-lang#1913, where we generate an infinitely deep
structure. The reduced template here doesn't really make any
sense and wouldn't be encountered in the wild quite like this.

Previously we generated opaque types for this case, so we didn't
run into that bug. We now generate higher-fidelity types and therefore
hit the problem.

I can't see any way to salvage the fundamentals of this test case
without the recursive problem, so I propose to remove it.
adetaylor added a commit to adetaylor/rust-bindgen that referenced this issue May 13, 2021
When dependent qualified types are supported, this runs into
a different bug, rust-lang#1913, where we generate an infinitely deep
structure. The reduced template here doesn't really make any
sense and wouldn't be encountered in the wild quite like this.

Previously we generated opaque types for this case, so we didn't
run into that bug. We now generate higher-fidelity types and therefore
hit the problem.

I can't see any way to salvage the fundamentals of this test case
without the recursive problem, so I propose to remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants