Skip to content

Commit 132a2c6

Browse files
committed
elaborate a bit on the (lack of) safety in 'Mmap::map'
1 parent d06ca0f commit 132a2c6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/rustc_data_structures/src/memmap.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ pub struct Mmap(Vec<u8>);
1111

1212
#[cfg(not(target_arch = "wasm32"))]
1313
impl Mmap {
14+
/// # Safety
15+
///
16+
/// The given file must not be mutated (i.e., not written, not truncated, ...) until the mapping is closed.
17+
///
18+
/// However in practice most callers do not ensure this, so uses of this function are likely unsound.
1419
#[inline]
1520
pub unsafe fn map(file: File) -> io::Result<Self> {
16-
// Safety: this is in fact not safe.
21+
// Safety: the caller must ensure that this is safe.
1722
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
1823
}
1924
}

0 commit comments

Comments
 (0)