Skip to content

Commit 06a7460

Browse files
committed
Mark some coverage-related bindings as safe
1 parent 79c9f6e commit 06a7460

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ use crate::coverageinfo::ffi;
66
use crate::llvm;
77

88
pub(crate) fn covmap_var_name() -> CString {
9-
CString::new(llvm::build_byte_buffer(|s| unsafe {
9+
CString::new(llvm::build_byte_buffer(|s| {
1010
llvm::LLVMRustCoverageWriteCovmapVarNameToString(s);
1111
}))
1212
.expect("covmap variable name should not contain NUL")
1313
}
1414

1515
pub(crate) fn covmap_section_name(llmod: &llvm::Module) -> CString {
16-
CString::new(llvm::build_byte_buffer(|s| unsafe {
16+
CString::new(llvm::build_byte_buffer(|s| {
1717
llvm::LLVMRustCoverageWriteCovmapSectionNameToString(llmod, s);
1818
}))
1919
.expect("covmap section name should not contain NUL")
2020
}
2121

2222
pub(crate) fn covfun_section_name(llmod: &llvm::Module) -> CString {
23-
CString::new(llvm::build_byte_buffer(|s| unsafe {
23+
CString::new(llvm::build_byte_buffer(|s| {
2424
llvm::LLVMRustCoverageWriteCovfunSectionNameToString(llmod, s);
2525
}))
2626
.expect("covfun section name should not contain NUL")
@@ -95,5 +95,5 @@ pub(crate) fn hash_bytes(bytes: &[u8]) -> u64 {
9595
/// as a raw numeric value. For historical reasons, the numeric value is 1 less
9696
/// than the number in the version's name, so `Version7` is actually `6u32`.
9797
pub(crate) fn mapping_version() -> u32 {
98-
unsafe { llvm::LLVMRustCoverageMappingVersion() }
98+
llvm::LLVMRustCoverageMappingVersion()
9999
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,13 +2115,17 @@ unsafe extern "C" {
21152115
NumBytes: size_t,
21162116
) -> u64;
21172117

2118-
pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
2119-
2120-
pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString);
2121-
2122-
pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
2118+
pub(crate) safe fn LLVMRustCoverageWriteCovmapSectionNameToString(
2119+
M: &Module,
2120+
OutStr: &RustString,
2121+
);
2122+
pub(crate) safe fn LLVMRustCoverageWriteCovfunSectionNameToString(
2123+
M: &Module,
2124+
OutStr: &RustString,
2125+
);
2126+
pub(crate) safe fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
21232127

2124-
pub(crate) fn LLVMRustCoverageMappingVersion() -> u32;
2128+
pub(crate) safe fn LLVMRustCoverageMappingVersion() -> u32;
21252129
pub(crate) fn LLVMRustDebugMetadataVersion() -> u32;
21262130
pub(crate) fn LLVMRustVersionMajor() -> u32;
21272131
pub(crate) fn LLVMRustVersionMinor() -> u32;

0 commit comments

Comments
 (0)