rust-lang / rust-lang/rust-bindgen

wrap-static-fns generates too many consts

Open
#2,973 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

When running bindgen --experimental --wrap-static-fns ... on the following function

static inline int arch_within_stack_frames(const void * const stack,
					   const void * const stackend,
					   const void *obj, unsigned long len)
{
	return 0;
}

bindgen 0.69.5 generates the following C code in extern.c

int arch_within_stack_frames__extern(const const void *const stack, const const void *const stackend, const void *obj, unsigned long len) { return arch_within_stack_frames(stack, stackend, obj, len); }

Which then fails to build with the following error

rust/extern.c:1036:44: error: duplicate ‘const’ declaration specifier [-Werror=duplicate-decl-specifier]
 1036 | int arch_within_stack_frames__extern(const const void *const stack, const const void *const stackend, const void *obj, unsigned long len) { return arch_within_stack_frames(stack, stackend, obj, len); }
      |                                            ^~~~~
rust/extern.c:1036:75: error: duplicate ‘const’ declaration specifier [-Werror=duplicate-decl-specifier]
 1036 | int arch_within_stack_frames__extern(const const void *const stack, const const void *const stackend, const void *obj, unsigned long len) { return arch_within_stack_frames(stack, stackend, obj, len); }
      |                                                                           ^~~~~
cc1: all warnings being treated as errors

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

Start with bindgen --experimental --wrap-static-fns using the C function shown in the issue, then inspect the generated extern.c wrapper. Confirm the generated declaration contains duplicate const qualifiers; done means the wrapper no longer emits duplicate const declarations and the generated C builds without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.