Skip to content

Commit 2671e8c

Browse files
committed
Auto merge of #26642 - remram44:doc-openoptions-missing-write, r=alexcrichton
Setting append without write doesn't give you a writeable file. Showing it as an example in the docs is confusing at best ([reddit](https://www.reddit.com/r/rust/comments/3bbz8w/why_is_writing_a_file_not_working_for_me/)) Using truncate (O_TRUNC) on a read-only file is an error on POSIX systems ("unspecified"). Note however that using create (O_CREAT) with read-only flags is fine. Related: #26103 (which IMHO is wrong; saying "append is different than write" when should simply be "append needs write". My vote is to make append imply write)
2 parents c1b8bd2 + 78ec055 commit 2671e8c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libstd/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl OpenOptions {
419419
/// ```no_run
420420
/// use std::fs::OpenOptions;
421421
///
422-
/// let file = OpenOptions::new().append(true).open("foo.txt");
422+
/// let file = OpenOptions::new().write(true).append(true).open("foo.txt");
423423
/// ```
424424
#[stable(feature = "rust1", since = "1.0.0")]
425425
pub fn append(&mut self, append: bool) -> &mut OpenOptions {
@@ -436,7 +436,7 @@ impl OpenOptions {
436436
/// ```no_run
437437
/// use std::fs::OpenOptions;
438438
///
439-
/// let file = OpenOptions::new().truncate(true).open("foo.txt");
439+
/// let file = OpenOptions::new().write(true).truncate(true).open("foo.txt");
440440
/// ```
441441
#[stable(feature = "rust1", since = "1.0.0")]
442442
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {

0 commit comments

Comments
 (0)