Skip to content

Enums shadowed by names in module #649

@mkeeter

Description

@mkeeter

I'm seeing misbehavior where an enum in a module causes mistranslation of a struct containing a #[repr(u32)] enum with the same name.

Here's a very simple test case:
test.rs:

mod uhoh {
    enum BindingType { Buffer, NotBuffer }
}

#[repr(u32)]
pub enum BindingType { Buffer = 0, NotBuffer = 1 }

#[repr(C)]
pub struct BindGroupLayoutEntry {
    pub ty: BindingType, // This is the repr(u32) enum
}

cbindgen.toml

language = "C"

[export]
include = [
    "BindGroupLayoutEntry",
]

Running cbindgen 0.16.0:

$ cbindgen -c cbindgen.toml test.rs
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

enum BindingType {
  Buffer = 0,
  NotBuffer = 1,
};
typedef uint32_t BindingType;

typedef struct BindGroupLayoutEntry {
  struct BindingType ty;
} BindGroupLayoutEntry;

Having the member be struct BindingType ty is invalid, because there is no struct BindingType in the header; it should instead be BindingType ty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions