rust-lang / rust-lang/rust-bindgen

Bindings fail to compile with 'cannot find type ... in this scope'

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

Nobody has claimed this yet.

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

Description

C++ header

template <typename a> struct b { static const a c; };
template <typename a> const a b<a>::c;

bindgen test-case-1.hpp -- -x c++ produces

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct b {
     pub _address: u8,
}
extern "C" {
    pub static c: a;
}

rustc --crate-type lib bindings.rs produces

error[E0412]: cannot find type `a` in this scope

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

Reproduce the issue with bindgen test-case-1.hpp -- -x c++, then compile the generated bindings.rs with rustc --crate-type lib. Inspect how the C++ template and static member are represented in the generated Rust output. Done means the reproduced binding no longer refers to an unresolved type and compiles successfully.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.