]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/docfs.rs
Rollup merge of #97616 - TaKO8Ki:remove-unnecessary-option, r=Dylan-DPC
[rust.git] / src / librustdoc / docfs.rs
index d59273db08b4f9f50fe7155816a55340893f3ed2..be066bdafa14a1bcf2b9d7876f0a8c6b35728a08 100644 (file)
 use std::string::ToString;
 use std::sync::mpsc::Sender;
 
-crate trait PathError {
+pub(crate) trait PathError {
     fn new<S, P: AsRef<Path>>(e: S, path: P) -> Self
     where
         S: ToString + Sized;
 }
 
-crate struct DocFS {
+pub(crate) struct DocFS {
     sync_only: bool,
     errors: Option<Sender<String>>,
 }
 
 impl DocFS {
-    crate fn new(errors: Sender<String>) -> DocFS {
+    pub(crate) fn new(errors: Sender<String>) -> DocFS {
         DocFS { sync_only: false, errors: Some(errors) }
     }
 
-    crate fn set_sync_only(&mut self, sync_only: bool) {
+    pub(crate) fn set_sync_only(&mut self, sync_only: bool) {
         self.sync_only = sync_only;
     }
 
-    crate fn close(&mut self) {
+    pub(crate) fn close(&mut self) {
         self.errors = None;
     }
 
-    crate fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
+    pub(crate) fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
         // For now, dir creation isn't a huge time consideration, do it
         // synchronously, which avoids needing ordering between write() actions
         // and directory creation.
         fs::create_dir_all(path)
     }
 
-    crate fn write<E>(
+    pub(crate) fn write<E>(
         &self,
         path: PathBuf,
         contents: impl 'static + Send + AsRef<[u8]>,
@@ -54,7 +54,8 @@ impl DocFS {
     where
         E: PathError,
     {
-        if !self.sync_only && cfg!(windows) {
+        #[cfg(windows)]
+        if !self.sync_only {
             // A possible future enhancement after more detailed profiling would
             // be to create the file sync so errors are reported eagerly.
             let sender = self.errors.clone().expect("can't write after closing");
@@ -68,6 +69,10 @@ impl DocFS {
         } else {
             fs::write(&path, contents).map_err(|e| E::new(e, path))?;
         }
+
+        #[cfg(not(windows))]
+        fs::write(&path, contents).map_err(|e| E::new(e, path))?;
+
         Ok(())
     }
 }