\
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index ed41b95e73f09..dcf36b5e865b9 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -2,6 +2,7 @@ use clean::AttributesExt;
use std::cmp::Ordering;
use std::fmt;
+use std::rc::Rc;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
@@ -60,7 +61,12 @@ struct ItemVars<'a> {
src_href: Option<&'a str>,
}
-pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, page: &Page<'_>) {
+pub(super) fn print_item(
+ cx: &mut Context<'_>,
+ item: &clean::Item,
+ buf: &mut Buffer,
+ page: &Page<'_>,
+) {
debug_assert!(!item.is_stripped());
let typ = match *item.kind {
clean::ModuleItem(_) => {
@@ -187,7 +193,7 @@ fn toggle_close(w: &mut Buffer) {
w.write_str("");
}
-fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) {
+fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: &[clean::Item]) {
document(w, cx, item, None, HeadingOffset::H2);
let mut indices = (0..items.len()).filter(|i| !items[*i].is_stripped()).collect::
>();
@@ -344,6 +350,12 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
let add = if stab.is_some() { " " } else { "" };
w.write_str(ITEM_TABLE_ROW_OPEN);
+ let id = match import.kind {
+ clean::ImportKind::Simple(s) => {
+ format!(" id=\"{}\"", cx.derive_id(format!("reexport.{}", s)))
+ }
+ clean::ImportKind::Glob => String::new(),
+ };
write!(
w,
"\
@@ -351,15 +363,9 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
\
{stab_tags}
",
stab = stab.unwrap_or_default(),
- add = add,
vis = myitem.visibility.print_with_space(myitem.item_id, cx),
imp = import.print(cx),
stab_tags = stab_tags.unwrap_or_default(),
- id = match import.kind {
- clean::ImportKind::Simple(s) =>
- format!(" id=\"{}\"", cx.derive_id(format!("reexport.{}", s))),
- clean::ImportKind::Glob => String::new(),
- },
);
w.write_str(ITEM_TABLE_ROW_CLOSE);
}
@@ -464,7 +470,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
tags
}
-fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
+fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
let header = it.fn_header(cx.tcx()).expect("printing a function which isn't a function");
let constness = print_constness_with_space(&header.constness, it.const_stability(cx.tcx()));
let unsafety = header.unsafety.print_with_space();
@@ -507,7 +513,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
document(w, cx, it, None, HeadingOffset::H2)
}
-fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) {
+fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Trait) {
let bounds = bounds(&t.bounds, false, cx);
let required_types = t.items.iter().filter(|m| m.is_ty_associated_type()).collect::>();
let provided_types = t.items.iter().filter(|m| m.is_associated_type()).collect::>();
@@ -674,7 +680,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
)
}
- fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item) {
+ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::Item) {
let name = m.name.unwrap();
info!("Documenting {} on {:?}", name, t.name);
let item_type = m.type_();
@@ -791,14 +797,15 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
// If there are methods directly on this trait object, render them here.
render_assoc_items(w, cx, it, it.item_id.expect_def_id(), AssocItemRender::All);
- let cache = cx.cache();
+ let cloned_shared = Rc::clone(&cx.shared);
+ let cache = &cloned_shared.cache;
let mut extern_crates = FxHashSet::default();
if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
// The DefId is for the first Type found with that name. The bool is
// if any Types with the same name but different DefId have been found.
let mut implementor_dups: FxHashMap = FxHashMap::default();
for implementor in implementors {
- if let Some(did) = implementor.inner_impl().for_.without_borrowed_ref().def_id(cx.cache()) &&
+ if let Some(did) = implementor.inner_impl().for_.without_borrowed_ref().def_id(cache) &&
!did.is_local() {
extern_crates.insert(did.krate);
}
@@ -996,7 +1003,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
);
}
-fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::TraitAlias) {
+fn item_trait_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TraitAlias) {
wrap_into_docblock(w, |w| {
wrap_item(w, "trait-alias", |w| {
render_attributes_in_pre(w, it, "");
@@ -1020,7 +1027,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
render_assoc_items(w, cx, it, it.item_id.expect_def_id(), AssocItemRender::All)
}
-fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) {
+fn item_opaque_ty(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) {
wrap_into_docblock(w, |w| {
wrap_item(w, "opaque", |w| {
render_attributes_in_pre(w, it, "");
@@ -1044,7 +1051,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
render_assoc_items(w, cx, it, it.item_id.expect_def_id(), AssocItemRender::All)
}
-fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
+fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Typedef) {
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
wrap_item(w, "typedef", |w| {
render_attributes_in_pre(w, it, "");
@@ -1073,7 +1080,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
document_type_layout(w, cx, def_id);
}
-fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) {
+fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Union) {
wrap_into_docblock(w, |w| {
wrap_item(w, "union", |w| {
render_attributes_in_pre(w, it, "");
@@ -1135,7 +1142,7 @@ fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]
}
}
-fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum) {
+fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::Enum) {
let count_variants = e.variants().count();
wrap_into_docblock(w, |w| {
wrap_item(w, "enum", |w| {
@@ -1283,7 +1290,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
document_type_layout(w, cx, def_id);
}
-fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Macro) {
+fn item_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Macro) {
wrap_into_docblock(w, |w| {
highlight::render_with_highlighting(
&t.source,
@@ -1300,7 +1307,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac
document(w, cx, it, None, HeadingOffset::H2)
}
-fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
+fn item_proc_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
wrap_into_docblock(w, |w| {
let name = it.name.expect("proc-macros always have names");
match m.kind {
@@ -1332,12 +1339,12 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean
document(w, cx, it, None, HeadingOffset::H2)
}
-fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
+fn item_primitive(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
document(w, cx, it, None, HeadingOffset::H2);
render_assoc_items(w, cx, it, it.item_id.expect_def_id(), AssocItemRender::All)
}
-fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::Constant) {
+fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &clean::Constant) {
wrap_into_docblock(w, |w| {
wrap_item(w, "const", |w| {
render_attributes_in_code(w, it);
@@ -1377,7 +1384,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
document(w, cx, it, None, HeadingOffset::H2)
}
-fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Struct) {
+fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Struct) {
wrap_into_docblock(w, |w| {
wrap_item(w, "struct", |w| {
render_attributes_in_code(w, it);
@@ -1430,7 +1437,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
document_type_layout(w, cx, def_id);
}
-fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Static) {
+fn item_static(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Static) {
wrap_into_docblock(w, |w| {
wrap_item(w, "static", |w| {
render_attributes_in_code(w, it);
@@ -1447,7 +1454,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
document(w, cx, it, None, HeadingOffset::H2)
}
-fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
+fn item_foreign_type(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
wrap_into_docblock(w, |w| {
wrap_item(w, "foreigntype", |w| {
w.write_str("extern {\n");
@@ -1466,7 +1473,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
render_assoc_items(w, cx, it, it.item_id.expect_def_id(), AssocItemRender::All)
}
-fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
+fn item_keyword(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
document(w, cx, it, None, HeadingOffset::H2)
}
@@ -1579,7 +1586,7 @@ fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> O
}
fn render_implementor(
- cx: &Context<'_>,
+ cx: &mut Context<'_>,
implementor: &Impl,
trait_: &clean::Item,
w: &mut Buffer,
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index ece659284d177..325d3a3143426 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -5,6 +5,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader};
use std::lazy::SyncLazy as Lazy;
use std::path::{Component, Path, PathBuf};
+use std::rc::Rc;
use itertools::Itertools;
use rustc_data_structures::flock;
@@ -135,7 +136,7 @@ impl Context<'_> {
}
pub(super) fn write_shared(
- cx: &Context<'_>,
+ cx: &mut Context<'_>,
krate: &Crate,
search_index: String,
options: &RenderOptions,
@@ -462,15 +463,16 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
crate::markdown::render(&index_page, md_opts, cx.shared.edition())
.map_err(|e| Error::new(e, &index_page))?;
} else {
+ let shared = Rc::clone(&cx.shared);
let dst = cx.dst.join("index.html");
let page = layout::Page {
title: "Index of crates",
css_class: "mod",
root_path: "./",
- static_root_path: cx.shared.static_root_path.as_deref(),
+ static_root_path: shared.static_root_path.as_deref(),
description: "List of crates",
keywords: BASIC_KEYWORDS,
- resource_suffix: &cx.shared.resource_suffix,
+ resource_suffix: &shared.resource_suffix,
extra_scripts: &[],
static_extra_scripts: &[],
};
@@ -490,8 +492,8 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
})
.collect::()
);
- let v = layout::render(&cx.shared.layout, &page, "", content, &cx.shared.style_files);
- cx.shared.fs.write(dst, v)?;
+ let v = layout::render(&shared.layout, &page, "", content, &shared.style_files);
+ shared.fs.write(dst, v)?;
}
}
diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs
index 0bbdc37ea8972..524c90e1f4d64 100644
--- a/src/librustdoc/html/sources.rs
+++ b/src/librustdoc/html/sources.rs
@@ -6,15 +6,18 @@ use crate::html::highlight;
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 @@ impl SourceCollector<'_, '_> {
// 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 @@ impl SourceCollector<'_, '_> {
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(())
}