Skip to content

Commit 19f7bb8

Browse files
committed
rust: str: remove from_bytes_with_nul_unwrap
This is part of the effort to minimize the differences of the `rust` branch with respect to mainline in order to eventually drop it. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent f99c223 commit 19f7bb8

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

rust/kernel/str.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,6 @@ impl CStr {
126126
Ok(unsafe { Self::from_bytes_with_nul_unchecked(bytes) })
127127
}
128128

129-
/// Creates a [`CStr`] from a `[u8]`, panic if input is not valid.
130-
///
131-
/// This function is only meant to be used by `c_str!` macro, so
132-
/// crates using `c_str!` macro don't have to enable `const_panic` feature.
133-
#[doc(hidden)]
134-
pub const fn from_bytes_with_nul_unwrap(bytes: &[u8]) -> &Self {
135-
match Self::from_bytes_with_nul(bytes) {
136-
Ok(v) => v,
137-
Err(_) => panic!("string contains interior NUL"),
138-
}
139-
}
140-
141129
/// Creates a [`CStr`] from a `[u8]` without performing any additional
142130
/// checks.
143131
///
@@ -346,7 +334,10 @@ where
346334
macro_rules! c_str {
347335
($str:expr) => {{
348336
const S: &str = concat!($str, "\0");
349-
const C: &$crate::str::CStr = $crate::str::CStr::from_bytes_with_nul_unwrap(S.as_bytes());
337+
const C: &$crate::str::CStr = match $crate::str::CStr::from_bytes_with_nul(S.as_bytes()) {
338+
Ok(v) => v,
339+
Err(_) => panic!("string contains interior NUL"),
340+
};
350341
C
351342
}};
352343
}

0 commit comments

Comments
 (0)