]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/fs.rs
Rollup merge of #107074 - lcnr:validate-dont-skip-opaque, r=compiler-errors
[rust.git] / library / std / src / fs.rs
index 6ddd5c28cc2d333baa2720385195454f40fc9770..286ad68fd13e8fdf70efab2fb31cb122ec23286d 100644 (file)
@@ -249,9 +249,8 @@ pub struct DirBuilder {
 pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
     fn inner(path: &Path) -> io::Result<Vec<u8>> {
         let mut file = File::open(path)?;
-        let mut bytes = Vec::new();
         let size = file.metadata().map(|m| m.len()).unwrap_or(0);
-        bytes.reserve(size as usize);
+        let mut bytes = Vec::with_capacity(size as usize);
         io::default_read_to_end(&mut file, &mut bytes)?;
         Ok(bytes)
     }
@@ -290,9 +289,8 @@ fn inner(path: &Path) -> io::Result<Vec<u8>> {
 pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
     fn inner(path: &Path) -> io::Result<String> {
         let mut file = File::open(path)?;
-        let mut string = String::new();
         let size = file.metadata().map(|m| m.len()).unwrap_or(0);
-        string.reserve(size as usize);
+        let mut string = String::with_capacity(size as usize);
         io::default_read_to_string(&mut file, &mut string)?;
         Ok(string)
     }
@@ -1514,7 +1512,7 @@ pub fn is_dir(&self) -> bool {
     }
 
     /// Tests whether this file type represents a regular file.
-    /// The result is  mutually exclusive to the results of
+    /// The result is mutually exclusive to the results of
     /// [`is_dir`] and [`is_symlink`]; only zero or one of these
     /// tests may pass.
     ///