Remove crate_name from DocContext
tcx.crate_name is the appropriate way to retrieve the crate name.
This commit is contained in:
parent
19c85a8f8a
commit
00d7bc7688
3 changed files with 8 additions and 13 deletions
|
@ -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
|
/// These names are used later on by HTML rendering to generate things like
|
||||||
/// source links back to the original item.
|
/// source links back to the original item.
|
||||||
pub fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKind) {
|
pub fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKind) {
|
||||||
let mut crate_name = cx.tcx.crate_name(did.krate).to_string();
|
let 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 relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
|
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
|
||||||
// extern blocks have an empty name
|
// extern blocks have an empty name
|
||||||
|
|
|
@ -46,8 +46,6 @@ pub struct DocContext<'tcx> {
|
||||||
|
|
||||||
pub tcx: TyCtxt<'tcx>,
|
pub tcx: TyCtxt<'tcx>,
|
||||||
pub resolver: Rc<RefCell<interface::BoxedResolver>>,
|
pub resolver: Rc<RefCell<interface::BoxedResolver>>,
|
||||||
/// The stack of module NodeIds up till this point
|
|
||||||
pub crate_name: Option<String>,
|
|
||||||
pub cstore: Lrc<CStore>,
|
pub cstore: Lrc<CStore>,
|
||||||
/// Later on moved into `html::render::CACHE_KEY`
|
/// Later on moved into `html::render::CACHE_KEY`
|
||||||
pub renderinfo: RefCell<RenderInfo>,
|
pub renderinfo: RefCell<RenderInfo>,
|
||||||
|
@ -332,7 +330,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
||||||
file_loader: None,
|
file_loader: None,
|
||||||
diagnostic_output: DiagnosticOutput::Default,
|
diagnostic_output: DiagnosticOutput::Default,
|
||||||
stderr: None,
|
stderr: None,
|
||||||
crate_name: crate_name.clone(),
|
crate_name,
|
||||||
lint_caps,
|
lint_caps,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -372,7 +370,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
||||||
let ctxt = DocContext {
|
let ctxt = DocContext {
|
||||||
tcx,
|
tcx,
|
||||||
resolver,
|
resolver,
|
||||||
crate_name,
|
|
||||||
cstore: compiler.cstore().clone(),
|
cstore: compiler.cstore().clone(),
|
||||||
external_traits: Default::default(),
|
external_traits: Default::default(),
|
||||||
active_extern_traits: Default::default(),
|
active_extern_traits: Default::default(),
|
||||||
|
|
|
@ -6,6 +6,7 @@ use rustc::hir::def::{Res, DefKind};
|
||||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc::middle::privacy::AccessLevel;
|
use rustc::middle::privacy::AccessLevel;
|
||||||
use rustc::util::nodemap::{FxHashSet, FxHashMap};
|
use rustc::util::nodemap::{FxHashSet, FxHashMap};
|
||||||
|
use rustc::ty::TyCtxt;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ext::base::MacroKind;
|
use syntax::ext::base::MacroKind;
|
||||||
use syntax::source_map::Spanned;
|
use syntax::source_map::Spanned;
|
||||||
|
@ -18,13 +19,13 @@ use crate::core;
|
||||||
use crate::clean::{self, AttributesExt, NestedAttributesExt};
|
use crate::clean::{self, AttributesExt, NestedAttributesExt};
|
||||||
use crate::doctree::*;
|
use crate::doctree::*;
|
||||||
|
|
||||||
|
// FIXME: Should this be replaced with tcx.def_path_str?
|
||||||
fn def_id_to_path(
|
fn def_id_to_path(
|
||||||
cx: &core::DocContext<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
did: DefId,
|
did: DefId,
|
||||||
name: Option<String>
|
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
|
let crate_name = tcx.crate_name(did.krate).to_string();
|
||||||
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
|
let relative = tcx.def_path(did).data.into_iter().filter_map(|elem| {
|
||||||
// extern blocks have an empty name
|
// extern blocks have an empty name
|
||||||
let s = elem.data.to_string();
|
let s = elem.data.to_string();
|
||||||
if !s.is_empty() {
|
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
|
// We can't use the entry API, as that keeps the mutable borrow of `self` active
|
||||||
// when we try to use `cx`.
|
// when we try to use `cx`.
|
||||||
if self.exact_paths.get(&did).is_none() {
|
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);
|
self.exact_paths.insert(did, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue