Skip to content

Commit 3976bd9

Browse files
authored
Merge pull request #492 from nbdd0121/rust
rust: remove usage of `const_raw_ptr_deref`
2 parents 9b7314a + 25ac90d commit 3976bd9

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

rust/kernel/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
const_fn_trait_bound,
2020
const_mut_refs,
2121
const_panic,
22-
const_raw_ptr_deref,
22+
const_fn_transmute,
2323
const_unreachable_unchecked,
2424
doc_cfg,
2525
ptr_metadata,

rust/kernel/str.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,8 @@ impl CStr {
146146
/// `NUL` byte (or the string will be truncated).
147147
#[inline]
148148
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
149-
// Note: This can be done using pointer deref (which requires
150-
// `const_raw_ptr_deref` to be const) or `transmute` (which requires
151-
// `const_transmute` to be const) or `ptr::from_raw_parts` (which
152-
// requires `ptr_metadata`).
153-
// While none of them are current stable, it is very likely that one of
154-
// them will eventually be.
155149
// SAFETY: Properties of `bytes` guaranteed by the safety precondition.
156-
unsafe { &*(bytes as *const [u8] as *const Self) }
150+
unsafe { core::mem::transmute(bytes) }
157151
}
158152

159153
/// Returns a C pointer to the string.

0 commit comments

Comments
 (0)