[Feature request] Provide an option to make bindgen generated default implementions inline
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
Research direction
The issue names no files or tests, so start by tracing bindgen's code path for generated Default implementations and its existing option plumbing. Add an option for applying #[inline(always)] to those implementations, then verify generated bindings differ only when the option is enabled.
Written by the indexing model from the issue text.
Description
When using the core #[derive(Default)] macro the implementation of default is always inlined:
https://doc.rust-lang.org/src/core/default.rs.html#150 :
($t:ty, $v:expr, $doc:tt) => {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
const impl Default for $t {
#[inline(always)]
#[doc = $doc]
fn default() -> $t {
$v
}
}
};
}
However bindgen must sometimes implement it's own default() implementation. Currently these are not marked #[inline(always)]. Often this isn't much of a problem, however it can become a problem when exporting functions that create these objects externally as the default implementation might be in a different object that isn't linked.
For example the Linux kernel uses bindgen to generate object files containing bindings, but doesn't always want to link these objects. In particular for loadable kernel modules - see the discussion at https://lore.kernel.org/rust-for-linux/[email protected]/ . This isn't a problem for implementations created via #[derive(Default)] as they are always inline, but bindgen generated implementations are not.
Therefore it would be nice if there was an option to have bindgen add #[inline(always)] to it's default implementations to match the behaviour of #[derive(Default)]
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 846
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from rust-lang/rust-bindgen
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)Possibly taken @lwz23 claimed this 47 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
rust-lang/rust-bindgen#3485 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-bindgen#3483 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
rust-lang/rust-bindgen#3370 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rust-lang/rust-bindgen#3363 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rust-lang/rust-bindgen#3540 ·
Maintainers usually reply within 1 day
All issues in rust-lang/rust-bindgen
Similar issues
-
good first issue help wanted program
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nautechsystems/nautilus_trader#5631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bytecodealliance/rustix#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
longbridge/gpui-kit#3871 ·
Maintainers usually reply within 1 day
-
area:models enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day