mozilla / mozilla/cbindgen

[Feature Request] Const of unit type generate "empty" defines

Open
#1,017 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3k
Forks
386
Avg merge
1h 43m
Merged PRs (30d)
1

Description

In my project, depending on the target some definitions should expand to nothing instead of a number.

I would like that if a const defined as a unit type generated an empty define:
const MYCONST: () = () —> #define MYCONST

Currently I'm using a hack, since I do have a header that are included on all other headers, I create a manual #define None and make the const equal to None. That in turns generate #define [NAME] None, in the grand scheme of things, C preprocessor expand to nothing, as expected. But would be nice to have something easier and less hacky.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace cbindgen's handling of Rust const items and unit types; no source file or test is named in the issue, so begin by locating the code and existing tests for generated #define values. Done means const MYCONST: () = () generates #define MYCONST, while existing non-unit constants retain their current output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.