Remove crate_name from DocContext

tcx.crate_name is the appropriate way to retrieve the crate name.
This commit is contained in:
Mark Rousskov 2019-08-10 13:44:23 -04:00
parent 19c85a8f8a
commit 00d7bc7688
3 changed files with 8 additions and 13 deletions

View file

@ -163,10 +163,7 @@ pub fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> {
/// These names are used later on by HTML rendering to generate things like
/// source links back to the original item.
pub fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKind) {
let mut crate_name = cx.tcx.crate_name(did.krate).to_string();
if did.is_local() {
crate_name = cx.crate_name.clone().unwrap_or(crate_name);
}
let crate_name = cx.tcx.crate_name(did.krate).to_string();
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
// extern blocks have an empty name

View file

@ -46,8 +46,6 @@ pub struct DocContext<'tcx> {
pub tcx: TyCtxt<'tcx>,
pub resolver: Rc<RefCell<interface::BoxedResolver>>,
/// The stack of module NodeIds up till this point
pub crate_name: Option<String>,
pub cstore: Lrc<CStore>,
/// Later on moved into `html::render::CACHE_KEY`
pub renderinfo: RefCell<RenderInfo>,
@ -332,7 +330,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
file_loader: None,
diagnostic_output: DiagnosticOutput::Default,
stderr: None,
crate_name: crate_name.clone(),
crate_name,
lint_caps,
};
@ -372,7 +370,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
let ctxt = DocContext {
tcx,
resolver,
crate_name,
cstore: compiler.cstore().clone(),
external_traits: Default::default(),
active_extern_traits: Default::default(),

View file

@ -6,6 +6,7 @@ use rustc::hir::def::{Res, DefKind};
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::middle::privacy::AccessLevel;
use rustc::util::nodemap::{FxHashSet, FxHashMap};
use rustc::ty::TyCtxt;
use syntax::ast;
use syntax::ext::base::MacroKind;
use syntax::source_map::Spanned;
@ -18,13 +19,13 @@ use crate::core;
use crate::clean::{self, AttributesExt, NestedAttributesExt};
use crate::doctree::*;
// FIXME: Should this be replaced with tcx.def_path_str?
fn def_id_to_path(
cx: &core::DocContext<'_>,
tcx: TyCtxt<'_>,
did: DefId,
name: Option<String>
) -> Vec<String> {
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
let crate_name = tcx.crate_name(did.krate).to_string();
let relative = tcx.def_path(did).data.into_iter().filter_map(|elem| {
// extern blocks have an empty name
let s = elem.data.to_string();
if !s.is_empty() {
@ -68,7 +69,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// We can't use the entry API, as that keeps the mutable borrow of `self` active
// when we try to use `cx`.
if self.exact_paths.get(&did).is_none() {
let path = def_id_to_path(self.cx, did, self.cx.crate_name.clone());
let path = def_id_to_path(self.cx.tcx, did);
self.exact_paths.insert(did, path);
}
}