Skip to content

Commit 82911a2

Browse files
mematthiasemilio
authored andcommitted
Emit const __BindgenUnionField accessors and comply with Rust 2024 unsafe-op-in-unsafe-fn
1 parent 23e2b01 commit 82911a2

File tree

6 files changed

+24
-33
lines changed

6 files changed

+24
-33
lines changed

bindgen-tests/tests/expectations/tests/disable-untagged-union.rs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/issue-493.rs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/transform-op.rs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen/codegen/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5527,38 +5527,29 @@ pub(crate) mod utils {
55275527
) {
55285528
let prefix = ctx.trait_prefix();
55295529

5530-
// If the target supports `const fn`, declare eligible functions
5531-
// as `const fn` else just `fn`.
5532-
let const_fn = if true {
5533-
quote! { const fn }
5534-
} else {
5535-
quote! { fn }
5536-
};
5537-
55385530
// TODO(emilio): The fmt::Debug impl could be way nicer with
55395531
// std::intrinsics::type_name, but...
55405532
let union_field_decl = quote! {
55415533
#[repr(C)]
55425534
pub struct __BindgenUnionField<T>(::#prefix::marker::PhantomData<T>);
55435535
};
55445536

5545-
let transmute =
5546-
ctx.wrap_unsafe_ops(quote!(::#prefix::mem::transmute(self)));
5537+
let transmute = quote!(unsafe { ::#prefix::mem::transmute(self) });
55475538

55485539
let union_field_impl = quote! {
55495540
impl<T> __BindgenUnionField<T> {
55505541
#[inline]
5551-
pub #const_fn new() -> Self {
5542+
pub const fn new() -> Self {
55525543
__BindgenUnionField(::#prefix::marker::PhantomData)
55535544
}
55545545

55555546
#[inline]
5556-
pub unsafe fn as_ref(&self) -> &T {
5547+
pub const unsafe fn as_ref(&self) -> &T {
55575548
#transmute
55585549
}
55595550

55605551
#[inline]
5561-
pub unsafe fn as_mut(&mut self) -> &mut T {
5552+
pub const unsafe fn as_mut(&mut self) -> &mut T {
55625553
#transmute
55635554
}
55645555
}

0 commit comments

Comments
 (0)