cbindgen
cbindgen copied to clipboard
Can't handle bitflags bits method calls correctly
bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MemoryProtection: u32 {
const NONE = 0;
/// Execute
const X = 1 << 0;
/// Read
const R = 1 << 1;
/// Write
const W = 1 << 2;
/// Copy
const C = 1 << 3;
/// Execute and Read
const XR = Self::X.bits() | Self::R.bits();
/// Execute, Read and Write
const XRW = Self::X.bits() | Self::R.bits() | Self::W.bits();
/// Execute, Write and Copy
const XWC = Self::X.bits() | Self::W.bits() | Self::C.bits();
/// Read and Write
const RW = Self::R.bits() | Self::W.bits();
/// Write and Copy
const WC = Self::W.bits() | Self::C.bits();
/// Read and Copy
const RC = Self::R.bits() | Self::C.bits();
/// Read, Write and Copy
const RWC = Self::R.bits() | Self::W.bits() | Self::C.bits();
}
}
Generates:
using MemoryProtection = uint32_t;
constexpr static const MemoryProtection MemoryProtection_NONE = (uint32_t)0;
/// Execute
constexpr static const MemoryProtection MemoryProtection_X = (uint32_t)(1 << 0);
/// Read
constexpr static const MemoryProtection MemoryProtection_R = (uint32_t)(1 << 1);
/// Write
constexpr static const MemoryProtection MemoryProtection_W = (uint32_t)(1 << 2);
/// Copy
constexpr static const MemoryProtection MemoryProtection_C = (uint32_t)(1 << 3);
/// Execute and Read
constexpr static const MemoryProtection MemoryProtection_XR = (uint32_t)((MemoryProtection_X).bits | (MemoryProtection_R).bits);
/// Execute, Read and Write
constexpr static const MemoryProtection MemoryProtection_XRW = (uint32_t)(((MemoryProtection_X).bits | (MemoryProtection_R).bits) | (MemoryProtection_W).bits);
/// Execute, Write and Copy
constexpr static const MemoryProtection MemoryProtection_XWC = (uint32_t)(((MemoryProtection_X).bits | (MemoryProtection_W).bits) | (MemoryProtection_C).bits);
/// Read and Write
constexpr static const MemoryProtection MemoryProtection_RW = (uint32_t)((MemoryProtection_R).bits | (MemoryProtection_W).bits);
/// Write and Copy
constexpr static const MemoryProtection MemoryProtection_WC = (uint32_t)((MemoryProtection_W).bits | (MemoryProtection_C).bits);
/// Read and Copy
constexpr static const MemoryProtection MemoryProtection_RC = (uint32_t)((MemoryProtection_R).bits | (MemoryProtection_C).bits);
/// Read, Write and Copy
constexpr static const MemoryProtection MemoryProtection_RWC = (uint32_t)(((MemoryProtection_R).bits | (MemoryProtection_W).bits) | (MemoryProtection_C).bits);
The Problem:
Prints .bits
mostly related to #881
This is because of the repr(transparent) right? repr(C) works right?
This is because of the repr(transparent) right? repr(C) works right?
Yup, that was the case, using repr(C) works. but repr(transparent) should be supported correct?
@emilio
Well, yeah, I'd consider this a bug. But it's a more general bug, not to do with bitflags in particular. Any repr(transparent) struct would hit this.
@emilio can you assign me this issue? I would love to solve it.