rust-lang / rust-lang/rust-bindgen

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

Open
#1,913 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-C++ A-templates bug
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

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> {

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with bindgen test-case-3.hpp -- -x c++, then compile the generated bindings.rs with rustc --crate-type lib. Compare the generated recursive field with the reported E0072 and E0391 errors. Done means the bindings generated from this C++ header compile without those errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.