[PATCH v4 5/7] rust: str: use transmute in `from_bytes_with_nul_unchecked_mut`

Alexandre Courbot posted 7 patches 3 months, 3 weeks ago
[PATCH v4 5/7] rust: str: use transmute in `from_bytes_with_nul_unchecked_mut`
Posted by Alexandre Courbot 3 months, 3 weeks ago
`from_bytes_with_nul_unchecked` also does this, so do the same for
symmetry. This was probably not done due to the unavailability of the
`const_mut_refs` feature at the time this code was introduced.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 rust/kernel/str.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 2640a050847e64bfd18c127a5a83b93f01f036bc..28f2f359ab23e6a926e88913e3cc9f481aa86037 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -290,7 +290,7 @@ pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, CStrConvertError
     #[inline]
     pub const unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut CStr {
         // SAFETY: Properties of `bytes` guaranteed by the safety precondition.
-        unsafe { &mut *(bytes as *mut [u8] as *mut CStr) }
+        unsafe { core::mem::transmute(bytes) }
     }
 
     /// Returns a C pointer to the string.

-- 
2.49.0