LukeMathWalker / LukeMathWalker/cheadergen
Structs with same name in different modules generate corrupt C header
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 34
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
```
mod m1 {
typedef struct { int a; int b; } Foo;
}
mod m2 {
typedef struct { int c; } Foo;
}
int foo_user(m1::Foo f1, m2::Foo f2) {
}
```
This is CO2 code, but I would expect it to happen in Rust as well.
Actual output:
```C
typedef struct Foo {
int32_t a;
int32_t b;
} Foo;
typedef struct Foo {
int32_t c;
} Foo;
int32_t foo_user(struct Foo f1, struct Foo f2);
```
Expected output:
```C
typedef struct m1_Foo {
int32_t a;
int32_t b;
} m1_Foo;
typedef struct m2_Foo {
int32_t c;
} m2_Foo;
int32_t foo_user(struct m1_Foo f1, struct m2_Foo f2);
```
Another valid option is to raise error and force the user to rename one of the structs using an attribute. But I guess I would prefer the auto disambiguation.
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
Start by reproducing the shown CO2 example and trace the header-generation entry point that emits both Foo definitions. Compare the generated C header with the expected m1_Foo and m2_Foo names, then determine how the issue should be handled and verify that the two module-scoped structs no longer collide.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100