X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustdoc%2Fhtml%2Frender%2Fmod.rs;h=76db0205695eff11f23446ea74d781c1b925db57;hb=a2fb4b95ddda1c2d622c809e63aa5e158cfb9976;hp=efee4c0be06d07ae7a5bde02e335f13da552e5c4;hpb=65d053ab74d8c8c9c502b678acc265f3d7e2ac49;p=rust.git diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index efee4c0be06..76db0205695 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -49,21 +49,24 @@ use itertools::Itertools; use rustc_ast_pretty::pprust; -use rustc_attr::StabilityLevel; +use rustc_attr::{Deprecation, StabilityLevel}; use rustc_data_structures::flock; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Mutability; use rustc_middle::middle::stability; +use rustc_middle::ty; +use rustc_middle::ty::TyCtxt; +use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::FileName; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::{kw, sym, Symbol}; use serde::ser::SerializeSeq; use serde::{Serialize, Serializer}; -use crate::clean::{self, AttributesExt, Deprecation, GetDefId, RenderedLink, SelfTy, TypeKind}; +use crate::clean::{self, AttributesExt, GetDefId, RenderedLink, SelfTy, TypeKind}; use crate::config::{RenderInfo, RenderOptions}; use crate::docfs::{DocFS, PathError}; use crate::doctree; @@ -100,7 +103,7 @@ /// easily cloned because it is cloned per work-job (about once per item in the /// rustdoc tree). #[derive(Clone)] -crate struct Context { +crate struct Context<'tcx> { /// Current hierarchy of components leading down to what's currently being /// rendered crate current: Vec, @@ -113,14 +116,15 @@ crate render_redirect_pages: bool, /// The map used to ensure all generated 'id=' attributes are unique. id_map: Rc>, - crate shared: Arc, + crate shared: Arc>, all: Rc>, /// Storage for the errors produced while generating documentation so they /// can be printed together at the end. crate errors: Rc>, } -crate struct SharedContext { +crate struct SharedContext<'tcx> { + crate tcx: TyCtxt<'tcx>, /// The path to the crate root source minus the file name. /// Used for simplifying paths to the highlighted source code files. crate src_root: PathBuf, @@ -160,7 +164,7 @@ playground: Option, } -impl Context { +impl<'tcx> Context<'tcx> { 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 @@ -171,9 +175,17 @@ fn path(&self, filename: &str) -> PathBuf { let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext); self.dst.join(&filename) } + + fn tcx(&self) -> TyCtxt<'tcx> { + self.shared.tcx + } + + fn sess(&self) -> &Session { + &self.shared.tcx.sess + } } -impl SharedContext { +impl SharedContext<'_> { crate fn ensure_dir(&self, dst: &Path) -> Result<(), Error> { let mut dirs = self.created_dirs.borrow_mut(); if !dirs.contains(dst) { @@ -374,14 +386,15 @@ fn serialize(&self, serializer: S) -> Result } /// Generates the documentation for `crate` into the directory `dst` -impl FormatRenderer for Context { +impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { fn init( mut krate: clean::Crate, options: RenderOptions, _render_info: RenderInfo, edition: Edition, cache: &mut Cache, - ) -> Result<(Context, clean::Crate), Error> { + tcx: ty::TyCtxt<'tcx>, + ) -> Result<(Self, clean::Crate), Error> { // need to save a copy of the options for rendering the index page let md_opts = options.clone(); let RenderOptions { @@ -410,14 +423,15 @@ fn init( // If user passed in `--playground-url` arg, we fill in crate name here let mut playground = None; if let Some(url) = playground_url { - playground = Some(markdown::Playground { crate_name: Some(krate.name.clone()), url }); + playground = + Some(markdown::Playground { crate_name: Some(krate.name.to_string()), url }); } let mut layout = layout::Layout { logo: String::new(), favicon: String::new(), external_html, default_settings, - krate: krate.name.clone(), + krate: krate.name.to_string(), css_file_extension: extension_css, generate_search_filter, }; @@ -437,7 +451,7 @@ fn init( } (sym::html_playground_url, Some(s)) => { playground = Some(markdown::Playground { - crate_name: Some(krate.name.clone()), + crate_name: Some(krate.name.to_string()), url: s.to_string(), }); } @@ -453,6 +467,7 @@ fn init( } let (sender, receiver) = channel(); let mut scx = SharedContext { + tcx, collapsed: krate.collapsed, src_root, include_sources, @@ -521,7 +536,7 @@ fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> { } fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> { - let final_file = self.dst.join(&krate.name).join("all.html"); + let final_file = self.dst.join(&*krate.name.as_str()).join("all.html"); let settings_file = self.dst.join("settings.html"); let crate_name = krate.name.clone(); @@ -656,7 +671,7 @@ fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> { if !buf.is_empty() { let name = item.name.as_ref().unwrap(); let item_type = item.type_(); - let file_name = &item_path(item_type, name); + let file_name = &item_path(item_type, &name.as_str()); self.shared.ensure_dir(&self.dst)?; let joint_dst = self.dst.join(file_name); self.shared.fs.write(&joint_dst, buf.as_bytes())?; @@ -678,7 +693,7 @@ fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> { } fn write_shared( - cx: &Context, + cx: &Context<'_>, krate: &clean::Crate, search_index: String, options: &RenderOptions, @@ -1010,7 +1025,8 @@ fn to_json_string(&self) -> String { } let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix)); - let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst); + let (mut all_sources, _krates) = + try_err!(collect(&dst, &krate.name.as_str(), "sourcesIndex"), &dst); all_sources.push(format!( "sourcesIndex[\"{}\"] = {};", &krate.name, @@ -1026,7 +1042,7 @@ fn to_json_string(&self) -> String { // Update the search index let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix)); - let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name), &dst); + let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst); all_indexes.push(search_index); // Sort the indexes by crate so the file will be generated identically even @@ -1061,7 +1077,7 @@ fn to_json_string(&self) -> String { extra_scripts: &[], static_extra_scripts: &[], }; - krates.push(krate.name.clone()); + krates.push(krate.name.to_string()); krates.sort(); krates.dedup(); @@ -1153,7 +1169,7 @@ struct Implementor { mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1])); let (mut all_implementors, _) = - try_err!(collect(&mydst, &krate.name, "implementors"), &mydst); + try_err!(collect(&mydst, &krate.name.as_str(), "implementors"), &mydst); all_implementors.push(implementors); // Sort the implementors by crate so the file will be generated // identically even with rustdoc running in parallel. @@ -1194,7 +1210,7 @@ fn write_minify( } } -fn write_srclink(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache) { +fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, cache: &Cache) { if let Some(l) = cx.src_href(item, cache) { write!( buf, @@ -1505,7 +1521,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result { fn derive_id(&self, id: String) -> String { let mut map = self.id_map.borrow_mut(); map.derive(id) @@ -1534,7 +1550,7 @@ fn render_item(&self, it: &clean::Item, pushname: bool, cache: &Cache) -> String if !title.is_empty() { title.push_str("::"); } - title.push_str(it.name.as_ref().unwrap()); + title.push_str(&it.name.unwrap().as_str()); } title.push_str(" - Rust"); let tyname = it.type_(); @@ -1629,26 +1645,27 @@ fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap Option { let mut root = self.root_path(); - let mut path = String::new(); + let cnum = item.source.cnum(self.sess()); // We can safely ignore synthetic `SourceFile`s. - let file = match item.source.filename { + let file = match item.source.filename(self.sess()) { FileName::Real(ref path) => path.local_path().to_path_buf(), _ => return None, }; let file = &file; - let (krate, path) = if item.source.cnum == LOCAL_CRATE { + let symbol; + let (krate, path) = if cnum == LOCAL_CRATE { if let Some(path) = self.shared.local_sources.get(file) { - (&self.shared.layout.krate, path) + (self.shared.layout.krate.as_str(), path) } else { return None; } } else { - let (krate, src_root) = match *cache.extern_locations.get(&item.source.cnum)? { - (ref name, ref src, ExternalLocation::Local) => (name, src), - (ref name, ref src, ExternalLocation::Remote(ref s)) => { + let (krate, src_root) = match *cache.extern_locations.get(&cnum)? { + (name, ref src, ExternalLocation::Local) => (name, src), + (name, ref src, ExternalLocation::Remote(ref s)) => { root = s.to_string(); (name, src) } @@ -1662,14 +1679,14 @@ fn src_href(&self, item: &clean::Item, cache: &Cache) -> Option { let mut fname = file.file_name().expect("source has no filename").to_os_string(); fname.push(".html"); path.push_str(&fname.to_string_lossy()); - (krate, &path) + symbol = krate.as_str(); + (&*symbol, &path) }; - let lines = if item.source.loline == item.source.hiline { - item.source.loline.to_string() - } else { - format!("{}-{}", item.source.loline, item.source.hiline) - }; + let loline = item.source.lo(self.sess()).line; + let hiline = item.source.hi(self.sess()).line; + let lines = + if loline == hiline { loline.to_string() } else { format!("{}-{}", loline, hiline) }; Some(format!( "{root}src/{krate}/{path}#{lines}", root = Escape(&root), @@ -1689,7 +1706,7 @@ fn wrap_into_docblock(w: &mut Buffer, f: F) write!(w, "") } -fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer, cache: &Cache) { +fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, cache: &Cache) { debug_assert!(!item.is_stripped()); // Write the breadcrumb trail header for the top write!(buf, "

"); @@ -1804,14 +1821,14 @@ fn item_path(ty: ItemType, name: &str) -> String { } } -fn full_path(cx: &Context, item: &clean::Item) -> String { +fn full_path(cx: &Context<'_>, item: &clean::Item) -> String { let mut s = cx.current.join("::"); s.push_str("::"); - s.push_str(item.name.as_ref().unwrap()); + s.push_str(&item.name.unwrap().as_str()); s } -fn document(w: &mut Buffer, cx: &Context, item: &clean::Item, parent: Option<&clean::Item>) { +fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option<&clean::Item>) { if let Some(ref name) = item.name { info!("Documenting {}", name); } @@ -1822,7 +1839,7 @@ fn document(w: &mut Buffer, cx: &Context, item: &clean::Item, parent: Option<&cl /// Render md_text as markdown. fn render_markdown( w: &mut Buffer, - cx: &Context, + cx: &Context<'_>, md_text: &str, links: Vec, prefix: &str, @@ -1851,7 +1868,7 @@ fn render_markdown( fn document_short( w: &mut Buffer, item: &clean::Item, - cx: &Context, + cx: &Context<'_>, link: AssocItemLink<'_>, prefix: &str, is_hidden: bool, @@ -1892,7 +1909,13 @@ fn document_short( } } -fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context, prefix: &str, is_hidden: bool) { +fn document_full( + w: &mut Buffer, + item: &clean::Item, + cx: &Context<'_>, + prefix: &str, + is_hidden: bool, +) { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { debug!("Doc block: =====\n{}\n=====", s); render_markdown(w, cx, &*s, item.links(), prefix, is_hidden); @@ -1913,7 +1936,7 @@ fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context, prefix: &str, /// * Required features (through the `doc_cfg` feature) fn document_item_info( w: &mut Buffer, - cx: &Context, + cx: &Context<'_>, item: &clean::Item, is_hidden: bool, parent: Option<&clean::Item>, @@ -2017,7 +2040,7 @@ fn take_parts<'a>(s: &mut &'a str) -> (&'a str, &'a str) { Ordering::Equal } -fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean::Item]) { +fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) { document(w, cx, item, None); let mut indices = (0..items.len()).filter(|i| !items[*i].is_stripped()).collect::>(); @@ -2057,9 +2080,9 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering (true, false) => return Ordering::Greater, } } - let lhs = i1.name.as_ref().map_or("", |s| &**s); - let rhs = i2.name.as_ref().map_or("", |s| &**s); - compare_names(lhs, rhs) + let lhs = i1.name.unwrap_or(kw::Invalid).as_str(); + let rhs = i2.name.unwrap_or(kw::Invalid).as_str(); + compare_names(&lhs, &rhs) } if cx.shared.sort_modules_alphabetically { @@ -2128,15 +2151,15 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering Some(ref src) => write!( w, "{}extern crate {} as {};", - myitem.visibility.print_with_space(), - anchor(myitem.def_id, src), + myitem.visibility.print_with_space(cx.tcx()), + anchor(myitem.def_id, &*src.as_str()), name ), None => write!( w, "{}extern crate {};", - myitem.visibility.print_with_space(), - anchor(myitem.def_id, name) + myitem.visibility.print_with_space(cx.tcx()), + anchor(myitem.def_id, &*name.as_str()) ), } write!(w, ""); @@ -2146,7 +2169,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering write!( w, "{}{}", - myitem.visibility.print_with_space(), + myitem.visibility.print_with_space(cx.tcx()), import.print() ); } @@ -2183,7 +2206,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering add = add, stab = stab.unwrap_or_else(String::new), unsafety_flag = unsafety_flag, - href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()), + href = item_path(myitem.type_(), &myitem.name.unwrap().as_str()), title = [full_path(cx, myitem), myitem.type_().to_string()] .iter() .filter_map(|s| if !s.is_empty() { Some(s.as_str()) } else { None }) @@ -2211,7 +2234,10 @@ fn tag_html(class: &str, title: &str, contents: &str) -> String { // The trailing space after each tag is to space it properly against the rest of the docs. if let Some(depr) = &item.deprecation { let mut message = "Deprecated"; - if !stability::deprecation_in_effect(depr.is_since_rustc_version, depr.since.as_deref()) { + if !stability::deprecation_in_effect( + depr.is_since_rustc_version, + depr.since.map(|s| s.as_str()).as_deref(), + ) { message = "Deprecation planned"; } tags += &tag_html("deprecated", "", message); @@ -2256,24 +2282,36 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option) -> Vec { +fn short_item_info( + item: &clean::Item, + cx: &Context<'_>, + parent: Option<&clean::Item>, +) -> Vec { let mut extra_info = vec![]; let error_codes = cx.shared.codes; - if let Some(Deprecation { ref note, ref since, is_since_rustc_version }) = item.deprecation { + if let Some(Deprecation { note, since, is_since_rustc_version, suggestion: _ }) = + item.deprecation + { // We display deprecation messages for #[deprecated] and #[rustc_deprecated] // but only display the future-deprecation messages for #[rustc_deprecated]. let mut message = if let Some(since) = since { + let since = &since.as_str(); if !stability::deprecation_in_effect(is_since_rustc_version, Some(since)) { - format!("Deprecating in {}", Escape(&since)) + if *since == "TBD" { + format!("Deprecating in a future Rust version") + } else { + format!("Deprecating in {}", Escape(since)) + } } else { - format!("Deprecated since {}", Escape(&since)) + format!("Deprecated since {}", Escape(since)) } } else { String::from("Deprecated") }; if let Some(note) = note { + let note = note.as_str(); let mut ids = cx.id_map.borrow_mut(); let html = MarkdownHtml( ¬e, @@ -2338,14 +2376,14 @@ fn short_item_info(item: &clean::Item, cx: &Context, parent: Option<&clean::Item extra_info } -fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Constant) { +fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::Constant) { write!(w, "
");
     render_attributes(w, it, false);
 
     write!(
         w,
         "{vis}const {name}: {typ}",
-        vis = it.visibility.print_with_space(),
+        vis = it.visibility.print_with_space(cx.tcx()),
         name = it.name.as_ref().unwrap(),
         typ = c.type_.print(),
     );
@@ -2373,13 +2411,13 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons
     document(w, cx, it, None)
 }
 
-fn item_static(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Static) {
+fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Static) {
     write!(w, "
");
     render_attributes(w, it, false);
     write!(
         w,
         "{vis}static {mutability}{name}: {typ}
", - vis = it.visibility.print_with_space(), + vis = it.visibility.print_with_space(cx.tcx()), mutability = s.mutability.print_with_space(), name = it.name.as_ref().unwrap(), typ = s.type_.print() @@ -2387,10 +2425,10 @@ fn item_static(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Static document(w, cx, it, None) } -fn item_function(w: &mut Buffer, cx: &Context, it: &clean::Item, f: &clean::Function) { +fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) { let header_len = format!( "{}{}{}{}{:#}fn {}{:#}", - it.visibility.print_with_space(), + it.visibility.print_with_space(cx.tcx()), f.header.constness.print_with_space(), f.header.asyncness.print_with_space(), f.header.unsafety.print_with_space(), @@ -2405,7 +2443,7 @@ fn item_function(w: &mut Buffer, cx: &Context, it: &clean::Item, f: &clean::Func w, "{vis}{constness}{asyncness}{unsafety}{abi}fn \ {name}{generics}{decl}{spotlight}{where_clause}
", - vis = it.visibility.print_with_space(), + vis = it.visibility.print_with_space(cx.tcx()), constness = f.header.constness.print_with_space(), asyncness = f.header.asyncness.print_with_space(), unsafety = f.header.unsafety.print_with_space(), @@ -2421,11 +2459,11 @@ fn item_function(w: &mut Buffer, cx: &Context, it: &clean::Item, f: &clean::Func } fn render_implementor( - cx: &Context, + cx: &Context<'_>, implementor: &Impl, parent: &clean::Item, w: &mut Buffer, - implementor_dups: &FxHashMap<&str, (DefId, bool)>, + implementor_dups: &FxHashMap, aliases: &[String], cache: &Cache, ) { @@ -2436,7 +2474,7 @@ fn render_implementor( | clean::BorrowedRef { type_: box clean::ResolvedPath { ref path, is_generic: false, .. }, .. - } => implementor_dups[path.last_name()].1, + } => implementor_dups[&path.last()].1, _ => false, }; render_impl( @@ -2458,7 +2496,7 @@ fn render_implementor( } fn render_impls( - cx: &Context, + cx: &Context<'_>, w: &mut Buffer, traits: &[&&Impl], containing_item: &clean::Item, @@ -2517,7 +2555,7 @@ fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering { compare_names(&lhs, &rhs) } -fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, cache: &Cache) { +fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait, cache: &Cache) { let bounds = bounds(&t.bounds, false); let types = t.items.iter().filter(|m| m.is_associated_type()).collect::>(); let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::>(); @@ -2531,7 +2569,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, write!( w, "{}{}{}trait {}{}{}", - it.visibility.print_with_space(), + it.visibility.print_with_space(cx.tcx()), t.unsafety.print_with_space(), if t.is_auto { "auto " } else { "" }, it.name.as_ref().unwrap(), @@ -2551,21 +2589,21 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, // FIXME: we should be using a derived_id for the Anchors here write!(w, "{{\n"); for t in &types { - render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait); + render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait, cx); write!(w, ";\n"); } if !types.is_empty() && !consts.is_empty() { w.write_str("\n"); } for t in &consts { - render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait); + render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait, cx); write!(w, ";\n"); } if !consts.is_empty() && !required.is_empty() { w.write_str("\n"); } for (pos, m) in required.iter().enumerate() { - render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait); + render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait, cx); write!(w, ";\n"); if pos < required.len() - 1 { @@ -2576,7 +2614,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, w.write_str("\n"); } for (pos, m) in provided.iter().enumerate() { - render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait); + render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait, cx); match m.kind { clean::MethodItem(ref inner, _) if !inner.generics.where_predicates.is_empty() => @@ -2613,13 +2651,19 @@ fn write_loading_content(w: &mut Buffer, extra_content: &str) { write!(w, "{}Loading content...", extra_content) } - fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item, cache: &Cache) { + fn trait_item( + w: &mut Buffer, + cx: &Context<'_>, + m: &clean::Item, + t: &clean::Item, + cache: &Cache, + ) { let name = m.name.as_ref().unwrap(); - info!("Documenting {} on {}", name, t.name.as_deref().unwrap_or_default()); + info!("Documenting {} on {:?}", name, t.name); let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); write!(w, "

", id = id,); - render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl); + render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx); write!(w, ""); render_stability_since(w, m, t); write_srclink(cx, m, w, cache); @@ -2685,7 +2729,7 @@ fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item, ca if let Some(implementors) = cache.implementors.get(&it.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<&str, (DefId, bool)> = FxHashMap::default(); + let mut implementor_dups: FxHashMap = FxHashMap::default(); for implementor in implementors { match implementor.inner_impl().for_ { clean::ResolvedPath { ref path, did, is_generic: false, .. } @@ -2694,7 +2738,7 @@ fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item, ca .. } => { let &mut (prev_did, ref mut has_duplicates) = - implementor_dups.entry(path.last_name()).or_insert((did, false)); + implementor_dups.entry(path.last()).or_insert((did, false)); if prev_did != did { *has_duplicates = true; } @@ -2837,12 +2881,13 @@ fn assoc_const( _default: Option<&String>, link: AssocItemLink<'_>, extra: &str, + cx: &Context<'_>, ) { write!( w, "{}{}const {}: {}", extra, - it.visibility.print_with_space(), + it.visibility.print_with_space(cx.tcx()), naive_assoc_href(it, link), it.name.as_ref().unwrap(), ty.print() @@ -2925,6 +2970,7 @@ fn render_assoc_item( item: &clean::Item, link: AssocItemLink<'_>, parent: ItemType, + cx: &Context<'_>, ) { fn method( w: &mut Buffer, @@ -2934,6 +2980,7 @@ fn method( d: &clean::FnDecl, link: AssocItemLink<'_>, parent: ItemType, + cx: &Context<'_>, ) { let name = meth.name.as_ref().unwrap(); let anchor = format!("#{}.{}", meth.type_(), name); @@ -2943,7 +2990,7 @@ fn method( AssocItemLink::GotoSource(did, provided_methods) => { // We're creating a link from an impl-item to the corresponding // trait-item and need to map the anchored type accordingly. - let ty = if provided_methods.contains(name) { + let ty = if provided_methods.contains(&*name.as_str()) { ItemType::Method } else { ItemType::TyMethod @@ -2954,7 +3001,7 @@ fn method( }; let mut header_len = format!( "{}{}{}{}{}{:#}fn {}{:#}", - meth.visibility.print_with_space(), + meth.visibility.print_with_space(cx.tcx()), header.constness.print_with_space(), header.asyncness.print_with_space(), header.unsafety.print_with_space(), @@ -2976,7 +3023,7 @@ fn method( "{}{}{}{}{}{}{}fn {name}\ {generics}{decl}{spotlight}{where_clause}", if parent == ItemType::Trait { " " } else { "" }, - meth.visibility.print_with_space(), + meth.visibility.print_with_space(cx.tcx()), header.constness.print_with_space(), header.asyncness.print_with_space(), header.unsafety.print_with_space(), @@ -2992,9 +3039,11 @@ fn method( } match item.kind { clean::StrippedItem(..) => {} - clean::TyMethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent), + clean::TyMethodItem(ref m) => { + method(w, item, m.header, &m.generics, &m.decl, link, parent, cx) + } clean::MethodItem(ref m, _) => { - method(w, item, m.header, &m.generics, &m.decl, link, parent) + method(w, item, m.header, &m.generics, &m.decl, link, parent, cx) } clean::AssocConstItem(ref ty, ref default) => assoc_const( w, @@ -3003,6 +3052,7 @@ fn method( default.as_ref(), link, if parent == ItemType::Trait { " " } else { "" }, + cx, ), clean::AssocTypeItem(ref bounds, ref default) => assoc_type( w, @@ -3016,11 +3066,17 @@ fn method( } } -fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct, cache: &Cache) { +fn item_struct( + w: &mut Buffer, + cx: &Context<'_>, + it: &clean::Item, + s: &clean::Struct, + cache: &Cache, +) { wrap_into_docblock(w, |w| { write!(w, "
");
         render_attributes(w, it, true);
-        render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true);
+        render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true, cx);
         write!(w, "
") }); @@ -3066,11 +3122,11 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache) } -fn item_union(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Union, cache: &Cache) { +fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union, cache: &Cache) { wrap_into_docblock(w, |w| { write!(w, "
");
         render_attributes(w, it, true);
-        render_union(w, it, Some(&s.generics), &s.fields, "", true);
+        render_union(w, it, Some(&s.generics), &s.fields, "", true, cx);
         write!(w, "
") }); @@ -3112,14 +3168,14 @@ fn item_union(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Union, render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache) } -fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum, cache: &Cache) { +fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum, cache: &Cache) { wrap_into_docblock(w, |w| { write!(w, "
");
         render_attributes(w, it, true);
         write!(
             w,
             "{}enum {}{}{}",
-            it.visibility.print_with_space(),
+            it.visibility.print_with_space(cx.tcx()),
             it.name.as_ref().unwrap(),
             e.generics.print(),
             WhereClause { gens: &e.generics, indent: 0, end_newline: true }
@@ -3145,7 +3201,7 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum, ca
                             write!(w, ")");
                         }
                         clean::VariantKind::Struct(ref s) => {
-                            render_struct(w, v, None, s.struct_type, &s.fields, "    ", false);
+                            render_struct(w, v, None, s.struct_type, &s.fields, "    ", false, cx);
                         }
                     },
                     _ => unreachable!(),
@@ -3289,11 +3345,12 @@ fn render_struct(
     fields: &[clean::Item],
     tab: &str,
     structhead: bool,
+    cx: &Context<'_>,
 ) {
     write!(
         w,
         "{}{}{}",
-        it.visibility.print_with_space(),
+        it.visibility.print_with_space(cx.tcx()),
         if structhead { "struct " } else { "" },
         it.name.as_ref().unwrap()
     );
@@ -3313,7 +3370,7 @@ fn render_struct(
                         w,
                         "\n{}    {}{}: {},",
                         tab,
-                        field.visibility.print_with_space(),
+                        field.visibility.print_with_space(cx.tcx()),
                         field.name.as_ref().unwrap(),
                         ty.print()
                     );
@@ -3342,7 +3399,7 @@ fn render_struct(
                 match field.kind {
                     clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
                     clean::StructFieldItem(ref ty) => {
-                        write!(w, "{}{}", field.visibility.print_with_space(), ty.print())
+                        write!(w, "{}{}", field.visibility.print_with_space(cx.tcx()), ty.print())
                     }
                     _ => unreachable!(),
                 }
@@ -3370,11 +3427,12 @@ fn render_union(
     fields: &[clean::Item],
     tab: &str,
     structhead: bool,
+    cx: &Context<'_>,
 ) {
     write!(
         w,
         "{}{}{}",
-        it.visibility.print_with_space(),
+        it.visibility.print_with_space(cx.tcx()),
         if structhead { "union " } else { "" },
         it.name.as_ref().unwrap()
     );
@@ -3389,7 +3447,7 @@ fn render_union(
             write!(
                 w,
                 "    {}{}: {},\n{}",
-                field.visibility.print_with_space(),
+                field.visibility.print_with_space(cx.tcx()),
                 field.name.as_ref().unwrap(),
                 ty.print(),
                 tab
@@ -3420,16 +3478,13 @@ fn anchor(&self, id: &'a String) -> Self {
 
 fn render_assoc_items(
     w: &mut Buffer,
-    cx: &Context,
+    cx: &Context<'_>,
     containing_item: &clean::Item,
     it: DefId,
     what: AssocItemRender<'_>,
     cache: &Cache,
 ) {
-    info!(
-        "Documenting associated items of {}",
-        containing_item.name.as_deref().unwrap_or_default()
-    );
+    info!("Documenting associated items of {:?}", containing_item.name);
     let v = match cache.impls.get(&it) {
         Some(v) => v,
         None => return,
@@ -3539,7 +3594,7 @@ fn render_assoc_items(
 
 fn render_deref_methods(
     w: &mut Buffer,
-    cx: &Context,
+    cx: &Context<'_>,
     impl_: &Impl,
     container_item: &clean::Item,
     deref_mut: bool,
@@ -3655,7 +3710,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
 
 fn render_impl(
     w: &mut Buffer,
-    cx: &Context,
+    cx: &Context<'_>,
     i: &Impl,
     parent: &clean::Item,
     link: AssocItemLink<'_>,
@@ -3749,7 +3804,7 @@ fn render_impl(
 
     fn doc_impl_item(
         w: &mut Buffer,
-        cx: &Context,
+        cx: &Context<'_>,
         item: &clean::Item,
         parent: &clean::Item,
         link: AssocItemLink<'_>,
@@ -3784,7 +3839,7 @@ fn doc_impl_item(
                     let id = cx.derive_id(format!("{}.{}", item_type, name));
                     write!(w, "

", id, item_type, extra_class); write!(w, ""); - render_assoc_item(w, item, link.anchor(&id), ItemType::Impl); + render_assoc_item(w, item, link.anchor(&id), ItemType::Impl, cx); write!(w, ""); render_stability_since_raw( w, @@ -3806,7 +3861,7 @@ fn doc_impl_item( clean::AssocConstItem(ref ty, ref default) => { let id = cx.derive_id(format!("{}.{}", item_type, name)); write!(w, "

", id, item_type, extra_class); - assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), ""); + assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "", cx); write!(w, ""); render_stability_since_raw( w, @@ -3886,7 +3941,7 @@ fn doc_impl_item( fn render_default_items( w: &mut Buffer, - cx: &Context, + cx: &Context<'_>, t: &clean::Trait, i: &clean::Impl, parent: &clean::Item, @@ -3946,7 +4001,7 @@ fn render_default_items( fn item_opaque_ty( w: &mut Buffer, - cx: &Context, + cx: &Context<'_>, it: &clean::Item, t: &clean::OpaqueTy, cache: &Cache, @@ -3973,7 +4028,7 @@ fn item_opaque_ty( fn item_trait_alias( w: &mut Buffer, - cx: &Context, + cx: &Context<'_>, it: &clean::Item, t: &clean::TraitAlias, cache: &Cache, @@ -3998,7 +4053,13 @@ fn item_trait_alias( render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache) } -fn item_typedef(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Typedef, cache: &Cache) { +fn item_typedef( + w: &mut Buffer, + cx: &Context<'_>, + it: &clean::Item, + t: &clean::Typedef, + cache: &Cache, +) { write!(w, "
");
     render_attributes(w, it, false);
     write!(
@@ -4019,13 +4080,13 @@ fn item_typedef(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Typed
     render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache)
 }
 
-fn item_foreign_type(w: &mut Buffer, cx: &Context, it: &clean::Item, cache: &Cache) {
+fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, cache: &Cache) {
     writeln!(w, "
extern {{");
     render_attributes(w, it, false);
     write!(
         w,
         "    {}type {};\n}}
", - it.visibility.print_with_space(), + it.visibility.print_with_space(cx.tcx()), it.name.as_ref().unwrap(), ); @@ -4034,7 +4095,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context, it: &clean::Item, cache: &Cac render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache) } -fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer, cache: &Cache) { +fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer, cache: &Cache) { let parentlen = cx.current.len() - if it.is_mod() { 1 } else { 0 }; if it.is_struct() @@ -4131,7 +4192,7 @@ fn print_sidebar(cx: &Context, it: &clean::Item, buffer: &mut Buffer, cache: &Ca ty: \"{ty}\", \ relpath: \"{path}\"\ }};", - name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""), + name = it.name.unwrap_or(kw::Invalid), ty = it.type_(), path = relpath ); @@ -4665,7 +4726,7 @@ fn sidebar_foreign_type(buf: &mut Buffer, it: &clean::Item) { } } -fn item_macro(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Macro) { +fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Macro) { wrap_into_docblock(w, |w| { w.write_str(&highlight::render_with_highlighting( t.source.clone(), @@ -4677,7 +4738,7 @@ fn item_macro(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Macro) document(w, cx, it, None) } -fn item_proc_macro(w: &mut Buffer, cx: &Context, it: &clean::Item, m: &clean::ProcMacro) { +fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) { let name = it.name.as_ref().expect("proc-macros always have names"); match m.kind { MacroKind::Bang => { @@ -4707,12 +4768,12 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context, it: &clean::Item, m: &clean::Pr document(w, cx, it, None) } -fn item_primitive(w: &mut Buffer, cx: &Context, it: &clean::Item, cache: &Cache) { +fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, cache: &Cache) { document(w, cx, it, None); render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All, cache) } -fn item_keyword(w: &mut Buffer, cx: &Context, it: &clean::Item) { +fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { document(w, cx, it, None) }