Add SharedResource abstraction and use it in write_shared

This cleans up the code quite a bit, and also makes the next commit much
easier.
This commit is contained in:
Joshua Nelson
2021-03-25 11:40:32 -04:00
parent bba40880c0
commit 7c89cc4a6f
2 changed files with 115 additions and 115 deletions

View File

@@ -79,17 +79,6 @@ crate struct Context<'tcx> {
rustc_data_structures::static_assert_size!(Context<'_>, 152);
impl<'tcx> Context<'tcx> {
pub(super) fn path(&self, filename: &str) -> PathBuf {
// We use splitn vs Path::extension here because we might get a filename
// like `style.min.css` and we want to process that into
// `style-suffix.min.css`. Path::extension would just return `css`
// which would result in `style.min-suffix.css` which isn't what we
// want.
let (base, ext) = filename.split_once('.').unwrap();
let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext);
self.dst.join(&filename)
}
pub(super) fn tcx(&self) -> TyCtxt<'tcx> {
self.shared.tcx
}
@@ -487,7 +476,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|buf: &mut Buffer| all.print(buf),
&self.shared.style_files,
);
self.shared.fs.write(&final_file, v.as_bytes())?;
self.shared.fs.write(final_file, v.as_bytes())?;
// Generating settings page.
page.title = "Rustdoc settings";