Skip to content

Commit 9e7d066

Browse files
committed
Simplify the args_cstr_buff assertion
1 parent 61932e1 commit 9e7d066

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::assert_matches::assert_matches;
12
use std::ffi::CStr;
23
use std::marker::PhantomData;
34
use std::ptr::NonNull;
@@ -41,11 +42,9 @@ impl OwnedTargetMachine {
4142
args_cstr_buff: &[u8],
4243
use_wasm_eh: bool,
4344
) -> Result<Self, LlvmError<'static>> {
44-
assert!(args_cstr_buff.len() > 0);
45-
assert!(
46-
*args_cstr_buff.last().unwrap() == 0,
47-
"The last character must be a null terminator."
48-
);
45+
// The argument list is passed as the concatenation of one or more C strings.
46+
// This implies that there must be a last byte, and it must be 0.
47+
assert_matches!(args_cstr_buff, [.., b'\0'], "the last byte must be a NUL terminator");
4948

5049
// SAFETY: llvm::LLVMRustCreateTargetMachine copies pointed to data
5150
let tm_ptr = unsafe {

0 commit comments

Comments
 (0)