Skip to content

Commit

Permalink
Remove crate_name from DocContext
Browse files Browse the repository at this point in the history
tcx.crate_name is the appropriate way to retrieve the crate name.
  • Loading branch information
Mark-Simulacrum committed Aug 11, 2019
1 parent 19c85a8 commit 00d7bc7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/core.rs
Expand Up @@ -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>,
Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/visit_ast.rs
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 00d7bc7

Please sign in to comment.