]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/html/sources.rs
Auto merge of #93717 - pietroalbini:pa-ci-profiler, r=Mark-Simulacrum
[rust.git] / src / librustdoc / html / sources.rs
index 0bbdc37ea8972d20d95cd4d46b4bfc57e6037ad2..524c90e1f4d644f62e6d37454595150462c96e89 100644 (file)
@@ -6,15 +6,18 @@
 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");
@@ -174,15 +177,16 @@ fn emit_source(
         // 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();
@@ -195,32 +199,33 @@ fn emit_source(
             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(())
     }