use crate::html::layout;
use crate::html::render::{Context, BASIC_KEYWORDS};
use crate::visit::DocVisitor;
+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::source_map::FileName;
+
use std::ffi::OsStr;
use std::fs;
use std::path::{Component, Path, PathBuf};
+use std::rc::Rc;
pub(crate) fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), Error> {
info!("emitting source files");
// Remove the utf-8 BOM if any
let contents = contents.strip_prefix('\u{feff}').unwrap_or(&contents);
+ let shared = Rc::clone(&self.cx.shared);
// Create the intermediate directories
let mut cur = self.dst.clone();
let mut root_path = String::from("../../");
- clean_path(&self.cx.shared.src_root, &p, false, |component| {
+ clean_path(&shared.src_root, &p, false, |component| {
cur.push(component);
root_path.push_str("../");
});
- self.cx.shared.ensure_dir(&cur)?;
+ shared.ensure_dir(&cur)?;
let src_fname = p.file_name().expect("source has no filename").to_os_string();
let mut fname = src_fname.clone();
title: &title,
css_class: "source",
root_path: &root_path,
- static_root_path: self.cx.shared.static_root_path.as_deref(),
+ static_root_path: shared.static_root_path.as_deref(),
description: &desc,
keywords: BASIC_KEYWORDS,
- resource_suffix: &self.cx.shared.resource_suffix,
- extra_scripts: &[&format!("source-files{}", self.cx.shared.resource_suffix)],
- static_extra_scripts: &[&format!("source-script{}", self.cx.shared.resource_suffix)],
+ resource_suffix: &shared.resource_suffix,
+ extra_scripts: &[&format!("source-files{}", shared.resource_suffix)],
+ static_extra_scripts: &[&format!("source-script{}", shared.resource_suffix)],
};
let v = layout::render(
- &self.cx.shared.layout,
+ &shared.layout,
&page,
"",
|buf: &mut _| {
+ let cx = &mut self.cx;
print_src(
buf,
contents,
- self.cx.shared.edition(),
+ cx.shared.edition(),
file_span,
- self.cx,
+ cx,
&root_path,
None,
SourceContext::Standalone,
)
},
- &self.cx.shared.style_files,
+ &shared.style_files,
);
- self.cx.shared.fs.write(cur, v)?;
+ shared.fs.write(cur, v)?;
self.emitted_local_sources.insert(p);
Ok(())
}