rust-lang / rust-lang/rust-bindgen
bindgen gets confused with arrays in generics.
Open
Nobody has claimed this yet.
A-libclang
bug
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
/// Header data with an inline length. Consumers that use HeaderWithLength as the
/// Header type in HeaderSlice can take advantage of ThinArc.
template<typename H>
struct StyleHeaderWithLength {
/// The fixed-sized data.
H header;
/// The slice length.
unsigned length;
bool operator==(const StyleHeaderWithLength& other) const {
return header == other.header &&
length == other.length;
}
bool operator!=(const StyleHeaderWithLength& other) const {
return header != other.header ||
length != other.length;
}
};
/// Structure to allow Arc-managing some fixed-sized data and a variably-sized
/// slice in a single allocation.
template<typename H, typename T>
struct StyleHeaderSlice {
/// The fixed-sized data.
H header;
/// The dynamically-sized data.
T slice;
bool operator==(const StyleHeaderSlice& other) const {
return header == other.header &&
slice == other.slice;
}
bool operator!=(const StyleHeaderSlice& other) const {
return header != other.header ||
slice != other.slice;
}
};
template<typename H, typename T>
using StyleHeaderSliceWithLength = StyleHeaderSlice<StyleHeaderWithLength<H>, T>;
/// The object allocated by an Arc<T>
template<typename T>
struct StyleArcInner {
unsigned count;
T data;
bool operator==(const StyleArcInner& other) const {
return count == other.count &&
data == other.data;
}
bool operator!=(const StyleArcInner& other) const {
return count != other.count ||
data != other.data;
}
};
template<typename H, typename T>
struct StyleThinArc {
StyleArcInner<StyleHeaderSliceWithLength<H, T[1]>> *ptr;
};
Bindgen Invocation
$ bindgen input.h
Actual Results
// ...
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StyleThinArc {
pub ptr: *mut StyleArcInner<T>,
}
Which obviously doesn't compile.
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.
Research direction
The reproduction is the C++ header shown in the issue; start by running bindgen input.h and comparing the generated StyleThinArc definition with the template declarations. Trace the generic-array handling that produces the invalid Rust type, then verify that the generated bindings compile for this input.
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
- 35/100