Can't handle bitflags bits method calls correctly
Open
Nobody has claimed this yet.
bug
help wanted
- Dominant language
- Rust
- Stars
- 3k
- Forks
- 386
- Avg merge
- 1h 43m
- Merged PRs (30d)
- 1
Description
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
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 with the bitflags example and trace how cbindgen translates method calls such as .bits() in generated constants. Compare the behavior with the related work in #881, then add regression coverage showing that bitflag method calls are emitted as valid constant expressions without the unwanted .bits text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100