Skip to content

Commit 78547d2

Browse files
committed
Auto merge of #26972 - jethrogb:patch-1, r=alexcrichton
The File object needs to be writable for the set_len to succeed.
2 parents da1b296 + 9262d64 commit 78547d2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libstd/fs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,18 @@ impl File {
269269
/// will be extended to `size` and have all of the intermediate data filled
270270
/// in with 0s.
271271
///
272+
/// # Errors
273+
///
274+
/// This function will return an error if the file is not opened for writing.
275+
///
272276
/// # Examples
273277
///
274278
/// ```no_run
275279
/// use std::fs::File;
276280
///
277281
/// # fn foo() -> std::io::Result<()> {
278-
/// let mut f = try!(File::open("foo.txt"));
279-
/// try!(f.set_len(0));
282+
/// let mut f = try!(File::create("foo.txt"));
283+
/// try!(f.set_len(10));
280284
/// # Ok(())
281285
/// # }
282286
/// ```

0 commit comments

Comments
 (0)