From 25ac90dd48d74565041bf0d0452404bca332daf1 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 6 Sep 2021 20:13:43 +0100 Subject: [PATCH] rust: remove usage of `const_raw_ptr_deref` Replace it with `const_fn_transmute` instead, which will be stable in Rust 1.56. Signed-off-by: Gary Guo --- rust/kernel/lib.rs | 2 +- rust/kernel/str.rs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index cda5f0e331c4ff..df5b8629fe0f9d 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -19,7 +19,7 @@ const_fn_trait_bound, const_mut_refs, const_panic, - const_raw_ptr_deref, + const_fn_transmute, const_unreachable_unchecked, doc_cfg, ptr_metadata, diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 5620080a8e81dc..ff5bc12f956802 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -146,14 +146,8 @@ impl CStr { /// `NUL` byte (or the string will be truncated). #[inline] pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr { - // Note: This can be done using pointer deref (which requires - // `const_raw_ptr_deref` to be const) or `transmute` (which requires - // `const_transmute` to be const) or `ptr::from_raw_parts` (which - // requires `ptr_metadata`). - // While none of them are current stable, it is very likely that one of - // them will eventually be. // SAFETY: Properties of `bytes` guaranteed by the safety precondition. - unsafe { &*(bytes as *const [u8] as *const Self) } + unsafe { core::mem::transmute(bytes) } } /// Returns a C pointer to the string.