Skip to content

defines is not applied for impl const  #955

@youknowone

Description

@youknowone

source (x.rs):

#[repr(C)]
pub struct Foo {
    a: i32,
    #[cfg(feature = "feat")]
    b: i32,
}

impl Foo {
    pub const ZEROED: Self = Self {
        a: 0,
        #[cfg(feature = "feat")]
        b: 0,
    };
}

cbindgen.toml:

[export]
include=["Foo"]

[defines]
"feature = feat" = "FEAT"

command:

cbindgen --config cbindgen.toml x.rs

actual result:

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct Foo {
  int32_t a;
#if defined(FEAT)
  int32_t b
#endif
  ;
};
constexpr static const Foo Foo_ZEROED = Foo{ /* .a = */ 0, /* .b = */ 0 };

expected result:

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct Foo {
  int32_t a;
#if defined(FEAT)
  int32_t b
#endif
  ;
};
constexpr static const Foo Foo_ZEROED = Foo{
  /* .a = */ 0,
#if defined(FEAT)
  /* .b = */ 0
#endif
};

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