Rollup merge of #153647 - TKanX:docs/153618-file-lock-cross-process, r=Mark-Simulacrum

docs(fs): Clarify That File::lock Coordinates Across Processes

### Summary:

The documentation for `lock`, `lock_shared`, `try_lock`, and `try_lock_shared` did not make it clear that these are OS level file locks that coordinate access across processes, not just between handles within the current process.

Add "in this or any other process" to each method's existing description to clarify this.

Fixes rust-lang/rust#153618

r? @Mark-Simulacrum
This commit is contained in:
Jonathan Brouwer
2026-03-23 12:14:57 +01:00
committed by GitHub
+8 -6
View File
@@ -815,7 +815,8 @@ pub fn sync_data(&self) -> io::Result<()> {
/// Acquire an exclusive lock on the file. Blocks until the lock can be acquired.
///
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
/// This acquires an exclusive lock; no other file handle to this file, in this or any other
/// process, may acquire another lock.
///
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
@@ -868,8 +869,8 @@ pub fn lock(&self) -> io::Result<()> {
/// Acquire a shared (non-exclusive) lock on the file. Blocks until the lock can be acquired.
///
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
/// hold an exclusive lock at the same time.
/// This acquires a shared lock; more than one file handle, in this or any other process, may
/// hold a shared lock, but none may hold an exclusive lock at the same time.
///
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
@@ -923,7 +924,8 @@ pub fn lock_shared(&self) -> io::Result<()> {
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
/// (via another handle/descriptor).
///
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
/// This acquires an exclusive lock; no other file handle to this file, in this or any other
/// process, may acquire another lock.
///
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
@@ -987,8 +989,8 @@ pub fn try_lock(&self) -> Result<(), TryLockError> {
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
/// (via another handle/descriptor).
///
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
/// hold an exclusive lock at the same time.
/// This acquires a shared lock; more than one file handle, in this or any other process, may
/// hold a shared lock, but none may hold an exclusive lock at the same time.
///
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with