diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 60636280e4..2148d94a35 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -7,12 +7,12 @@ impl __BindgenUnionField { __BindgenUnionField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + pub const unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + pub const unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index d2e4ea5375..7b297161ad 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -7,12 +7,12 @@ impl __BindgenUnionField { __BindgenUnionField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + pub const unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + pub const unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 7a12f2abb7..e1d27d15a4 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -7,12 +7,12 @@ impl __BindgenUnionField { __BindgenUnionField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + pub const unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + pub const unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index d13c24d2d8..32cb4fc586 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -7,12 +7,12 @@ impl __BindgenUnionField { __BindgenUnionField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + pub const unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + pub const unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs b/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs index aa23fcd734..c3395d9143 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs @@ -7,12 +7,12 @@ impl __BindgenUnionField { __BindgenUnionField(::std::marker::PhantomData) } #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + pub const unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } } #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + pub const unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 75801ad117..a28f5b33e5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5527,14 +5527,6 @@ 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! { @@ -5542,23 +5534,22 @@ pub(crate) mod utils { pub struct __BindgenUnionField(::#prefix::marker::PhantomData); }; - 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 __BindgenUnionField { #[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 } }