rust-lang / rust-lang/rust-bindgen
__attribute__((aligned(__alignof__(struct {...})))) will trigger size check error
Open
@armoha is already working on this.
Since Jul 7, 2026.
bug
help wanted
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
bindgen version and cargo build output:
PS C:\Users\admin\Desktop\rust_test\bindgen_bug> cargo build
Compiling bindgen_bug v0.1.0 (C:\Users\admin\Desktop\rust_test\bindgen_bug)
warning: unused import: `bugtest::*`
--> src\main.rs:2:5
|
2 | use bugtest::*;
| ^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0080]: index out of bounds: the length is 1 but the index is 4
--> src\bugtest.rs:30:5
|
30 | ["Size of base_t__bindgen_ty_1"][::std::mem::size_of::<base_t__bindgen_ty_1>() - 4usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `bugtest::_` failed here
error[E0080]: index out of bounds: the length is 1 but the index is 4
--> src\bugtest.rs:37:5
|
37 | ["Size of base_t"][::std::mem::size_of::<base_t>() - 4usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `bugtest::_` failed here
For more information about this error, try `rustc --explain E0080`.
warning: `bindgen_bug` (bin "bindgen_bug") generated 1 warning
error: could not compile `bindgen_bug` (bin "bindgen_bug") due to 2 previous errors; 1 warning emitted
PS C:\Users\admin\Desktop\rust_test\bindgen_bug> bindgen --version
bindgen 0.72.1
C header:
typedef struct base_t {
struct {
int aaa;
} __attribute__((aligned(
__alignof__(
struct {int aaa;}
)
)));
} base_t;
build.rs
use std::path::Path;
use std::env;
fn main() {
let bindings = bindgen::Builder::default()
.header("./test.h")
.generate().expect("Fail to convert test.h to rust header");
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let pathbuf = Path::new(&manifest_dir).join("./src/bugtest.rs");
bindings.write_to_file(&pathbuf).unwrap();
}
Cargo.toml:
[package]
name = "bindgen_bug"
version = "0.1.0"
edition = "2024"
[dependencies]
[build-dependencies]
bindgen = "0.72.1"
main.rs
mod bugtest;
use bugtest::*;
fn main() {
println!("Hello, world!");
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.