Emit const __BindgenUnionField accessors and comply with Rust 2024 unsafe-op-in-unsafe-fn
diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs
index 6063628..2148d94 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 @@
         __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<T> ::std::default::Default for __BindgenUnionField<T> {
diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs
index d2e4ea5..7b29716 100644
--- a/bindgen-tests/tests/expectations/tests/issue-493.rs
+++ b/bindgen-tests/tests/expectations/tests/issue-493.rs
@@ -7,12 +7,12 @@
         __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<T> ::std::default::Default for __BindgenUnionField<T> {
diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs
index 7a12f2a..e1d27d1 100644
--- a/bindgen-tests/tests/expectations/tests/transform-op.rs
+++ b/bindgen-tests/tests/expectations/tests/transform-op.rs
@@ -7,12 +7,12 @@
         __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<T> ::std::default::Default for __BindgenUnionField<T> {
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 d13c24d..32cb4fc 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 @@
         __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<T> ::std::default::Default for __BindgenUnionField<T> {
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 aa23fcd..c3395d9 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 @@
         __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<T> ::std::default::Default for __BindgenUnionField<T> {
diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs
index 75801ad..a28f5b3 100644
--- a/bindgen/codegen/mod.rs
+++ b/bindgen/codegen/mod.rs
@@ -5527,14 +5527,6 @@
     ) {
         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 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
                 }
             }