]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/html/sources.rs
Rollup merge of #68500 - Mark-Simulacrum:fix-bootstrap-clearing, r=alexcrichton
[rust.git] / src / librustdoc / html / sources.rs
index d840683a7af87575bf6b367089969d07a02d1a8f..79e7d3d783b807e422d19bab59008e9ebc7ac19a 100644 (file)
@@ -1,24 +1,24 @@
 use crate::clean;
 use crate::docfs::PathError;
 use crate::fold::DocFolder;
+use crate::html::format::Buffer;
+use crate::html::highlight;
 use crate::html::layout;
 use crate::html::render::{Error, SharedContext, BASIC_KEYWORDS};
-use crate::html::highlight;
-use crate::html::format::Buffer;
+use rustc_span::source_map::FileName;
 use std::ffi::OsStr;
 use std::fs;
 use std::path::{Component, Path, PathBuf};
-use syntax::source_map::FileName;
 
-crate fn render(dst: &Path, scx: &mut SharedContext,
-                  krate: clean::Crate) -> Result<clean::Crate, Error> {
+crate fn render(
+    dst: &Path,
+    scx: &mut SharedContext,
+    krate: clean::Crate,
+) -> Result<clean::Crate, Error> {
     info!("emitting source files");
     let dst = dst.join("src").join(&krate.name);
     scx.ensure_dir(&dst)?;
-    let mut folder = SourceCollector {
-        dst,
-        scx,
-    };
+    let mut folder = SourceCollector { dst, scx };
     Ok(folder.fold_crate(krate))
 }
 
@@ -38,20 +38,21 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
             // skip all invalid or macro spans
             && item.source.filename.is_real()
             // skip non-local items
-            && item.def_id.is_local() {
-
+            && item.def_id.is_local()
+        {
             // If it turns out that we couldn't read this file, then we probably
             // can't read any of the files (generating html output from json or
             // something like that), so just don't include sources for the
             // entire crate. The other option is maintaining this mapping on a
             // per-file basis, but that's probably not worth it...
-            self.scx
-                .include_sources = match self.emit_source(&item.source.filename) {
+            self.scx.include_sources = match self.emit_source(&item.source.filename) {
                 Ok(()) => true,
                 Err(e) => {
-                    println!("warning: source code was requested to be rendered, \
+                    println!(
+                        "warning: source code was requested to be rendered, \
                               but processing `{}` had an error: {}",
-                             item.source.filename, e);
+                        item.source.filename, e
+                    );
                     println!("         skipping rendering of source code");
                     false
                 }
@@ -81,11 +82,8 @@ fn emit_source(&mut self, filename: &FileName) -> Result<(), Error> {
         };
 
         // Remove the utf-8 BOM if any
-        let contents = if contents.starts_with("\u{feff}") {
-            &contents[3..]
-        } else {
-            &contents[..]
-        };
+        let contents =
+            if contents.starts_with("\u{feff}") { &contents[3..] } else { &contents[..] };
 
         // Create the intermediate directories
         let mut cur = self.dst.clone();
@@ -98,15 +96,15 @@ fn emit_source(&mut self, filename: &FileName) -> Result<(), Error> {
             href.push('/');
         });
         self.scx.ensure_dir(&cur)?;
-        let mut fname = p.file_name()
-                         .expect("source has no filename")
-                         .to_os_string();
+        let mut fname = p.file_name().expect("source has no filename").to_os_string();
         fname.push(".html");
         cur.push(&fname);
         href.push_str(&fname.to_string_lossy());
 
-        let title = format!("{} -- source", cur.file_name().expect("failed to get file name")
-                                               .to_string_lossy());
+        let title = format!(
+            "{} -- source",
+            cur.file_name().expect("failed to get file name").to_string_lossy()
+        );
         let desc = format!("Source to the Rust file `{}`.", filename);
         let page = layout::Page {
             title: &title,
@@ -119,9 +117,13 @@ fn emit_source(&mut self, filename: &FileName) -> Result<(), Error> {
             extra_scripts: &[&format!("source-files{}", self.scx.resource_suffix)],
             static_extra_scripts: &[&format!("source-script{}", self.scx.resource_suffix)],
         };
-        let v = layout::render(&self.scx.layout,
-                       &page, "", |buf: &mut _| print_src(buf, &contents),
-                       &self.scx.themes);
+        let v = layout::render(
+            &self.scx.layout,
+            &page,
+            "",
+            |buf: &mut _| print_src(buf, &contents),
+            &self.scx.themes,
+        );
         self.scx.fs.write(&cur, v.as_bytes())?;
         self.scx.local_sources.insert(p.clone(), href);
         Ok(())
@@ -170,6 +172,5 @@ fn print_src(buf: &mut Buffer, s: &str) {
         write!(buf, "<span id=\"{0}\">{0:1$}</span>\n", i, cols);
     }
     write!(buf, "</pre>");
-    write!(buf, "{}",
-            highlight::render_with_highlighting(s, None, None, None));
+    write!(buf, "{}", highlight::render_with_highlighting(s, None, None, None));
 }