diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/librustdoc/html/sources.rs | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
| download | rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip | |
Format the world
Diffstat (limited to 'src/librustdoc/html/sources.rs')
| -rw-r--r-- | src/librustdoc/html/sources.rs | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index d840683a7af..717fc7fbabd 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -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 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 @@ impl<'a> DocFolder for SourceCollector<'a> { // 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 @@ impl<'a> SourceCollector<'a> { }; // 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 @@ impl<'a> SourceCollector<'a> { 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 @@ impl<'a> SourceCollector<'a> { 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)); } |
