diff options
| author | Camelid <camelidcamel@gmail.com> | 2021-03-23 11:04:09 -0700 |
|---|---|---|
| committer | Camelid <camelidcamel@gmail.com> | 2021-03-23 11:04:09 -0700 |
| commit | 68244fc521c91b5daba347a4160a884eab268e08 (patch) | |
| tree | 26e8ade96ed1ff2f0c6709b0668ee8b68e615cb0 /src/librustdoc/html/render | |
| parent | c9ae35978c8520227b360830ff6971f2887c98a2 (diff) | |
| download | rust-68244fc521c91b5daba347a4160a884eab268e08.tar.gz rust-68244fc521c91b5daba347a4160a884eab268e08.zip | |
Remove unnecessary `Option` wrapping around `Crate.module`
I'm wondering if it was originally there so that we could `take` the module which enables `after_krate` to take an `&Crate`. However, the two impls of `after_krate` only use `Crate.name`, so we can pass just the name instead.
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/cache.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/html/render/context.rs | 53 |
2 files changed, 27 insertions, 33 deletions
diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 56fee2c9fec..5d49a494727 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -127,11 +127,8 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< crate_items.push(&*item); } - let crate_doc = krate - .module - .as_ref() - .map(|module| module.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s))) - .unwrap_or_default(); + let crate_doc = + krate.module.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s)); struct CrateData<'a> { doc: String, diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 864fbccbcc4..a18edda5561 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::source_map::FileName; -use rustc_span::symbol::sym; +use rustc_span::{symbol::sym, Symbol}; use super::cache::{build_index, ExternalLocation}; use super::print_item::{full_path, item_path, print_item}; @@ -343,29 +343,27 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { // Crawl the crate attributes looking for attributes which control how we're // going to emit HTML - if let Some(attrs) = krate.module.as_ref().map(|m| &m.attrs) { - for attr in attrs.lists(sym::doc) { - match (attr.name_or_empty(), attr.value_str()) { - (sym::html_favicon_url, Some(s)) => { - layout.favicon = s.to_string(); - } - (sym::html_logo_url, Some(s)) => { - layout.logo = s.to_string(); - } - (sym::html_playground_url, Some(s)) => { - playground = Some(markdown::Playground { - crate_name: Some(krate.name.to_string()), - url: s.to_string(), - }); - } - (sym::issue_tracker_base_url, Some(s)) => { - issue_tracker_base_url = Some(s.to_string()); - } - (sym::html_no_source, None) if attr.is_word() => { - include_sources = false; - } - _ => {} + for attr in krate.module.attrs.lists(sym::doc) { + match (attr.name_or_empty(), attr.value_str()) { + (sym::html_favicon_url, Some(s)) => { + layout.favicon = s.to_string(); + } + (sym::html_logo_url, Some(s)) => { + layout.logo = s.to_string(); + } + (sym::html_playground_url, Some(s)) => { + playground = Some(markdown::Playground { + crate_name: Some(krate.name.to_string()), + url: s.to_string(), + }); + } + (sym::issue_tracker_base_url, Some(s)) => { + issue_tracker_base_url = Some(s.to_string()); + } + (sym::html_no_source, None) if attr.is_word() => { + include_sources = false; } + _ => {} } } let (sender, receiver) = channel(); @@ -447,12 +445,11 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { fn after_krate( &mut self, - krate: &clean::Crate, + crate_name: Symbol, diag: &rustc_errors::Handler, ) -> Result<(), Error> { - let final_file = self.dst.join(&*krate.name.as_str()).join("all.html"); + let final_file = self.dst.join(&*crate_name.as_str()).join("all.html"); let settings_file = self.dst.join("settings.html"); - let crate_name = krate.name; let mut root_path = self.dst.to_str().expect("invalid path").to_owned(); if !root_path.ends_with('/') { @@ -515,9 +512,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { if let Some(ref redirections) = self.shared.redirections { if !redirections.borrow().is_empty() { let redirect_map_path = - self.dst.join(&*krate.name.as_str()).join("redirect-map.json"); + self.dst.join(&*crate_name.as_str()).join("redirect-map.json"); let paths = serde_json::to_string(&*redirections.borrow()).unwrap(); - self.shared.ensure_dir(&self.dst.join(&*krate.name.as_str()))?; + self.shared.ensure_dir(&self.dst.join(&*crate_name.as_str()))?; self.shared.fs.write(&redirect_map_path, paths.as_bytes())?; } } |
