Skip to content

Commit 3dad72c

Browse files
jhprattgitbot
authored and
gitbot
committed
Rollup merge of rust-lang#136704 - benschulz:patch-1, r=ibraheemdev
Improve examples for file locking The `lock` and `try_lock` documentation states that "if the file not open for writing, it is unspecified whether this function returns an error." With this change, the examples use `File::create` instead of `File::open`, eliminating the possibility of someone blindly copying code with unspecified behavior.
2 parents 2ed2402 + 3e4df80 commit 3dad72c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: std/src/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl File {
664664
/// use std::fs::File;
665665
///
666666
/// fn main() -> std::io::Result<()> {
667-
/// let f = File::open("foo.txt")?;
667+
/// let f = File::create("foo.txt")?;
668668
/// f.lock()?;
669669
/// Ok(())
670670
/// }
@@ -767,7 +767,7 @@ impl File {
767767
/// use std::fs::File;
768768
///
769769
/// fn main() -> std::io::Result<()> {
770-
/// let f = File::open("foo.txt")?;
770+
/// let f = File::create("foo.txt")?;
771771
/// f.try_lock()?;
772772
/// Ok(())
773773
/// }

0 commit comments

Comments
 (0)