Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bindgen-tests/tests/expectations/tests/issue-493.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bindgen-tests/tests/expectations/tests/transform-op.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5527,38 +5527,29 @@ pub(crate) mod utils {
) {
let prefix = ctx.trait_prefix();

// If the target supports `const fn`, declare eligible functions
// as `const fn` else just `fn`.
let const_fn = if true {
quote! { const fn }
} else {
quote! { fn }
};

// TODO(emilio): The fmt::Debug impl could be way nicer with
// std::intrinsics::type_name, but...
let union_field_decl = quote! {
#[repr(C)]
pub struct __BindgenUnionField<T>(::#prefix::marker::PhantomData<T>);
};

let transmute =
ctx.wrap_unsafe_ops(quote!(::#prefix::mem::transmute(self)));
let transmute = quote!(unsafe { ::#prefix::mem::transmute(self) });

let union_field_impl = quote! {
impl<T> __BindgenUnionField<T> {
#[inline]
pub #const_fn new() -> Self {
pub const fn new() -> Self {
__BindgenUnionField(::#prefix::marker::PhantomData)
}

#[inline]
pub unsafe fn as_ref(&self) -> &T {
pub const unsafe fn as_ref(&self) -> &T {
#transmute
}

#[inline]
pub unsafe fn as_mut(&mut self) -> &mut T {
pub const unsafe fn as_mut(&mut self) -> &mut T {
#transmute
}
}
Expand Down