Skip to content

Commit 00d7bc7

Browse files
Remove crate_name from DocContext
tcx.crate_name is the appropriate way to retrieve the crate name.
1 parent 19c85a8 commit 00d7bc7

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ pub fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> {
163163
/// These names are used later on by HTML rendering to generate things like
164164
/// source links back to the original item.
165165
pub fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKind) {
166-
let mut crate_name = cx.tcx.crate_name(did.krate).to_string();
167-
if did.is_local() {
168-
crate_name = cx.crate_name.clone().unwrap_or(crate_name);
169-
}
166+
let crate_name = cx.tcx.crate_name(did.krate).to_string();
170167

171168
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
172169
// extern blocks have an empty name

src/librustdoc/core.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ pub struct DocContext<'tcx> {
4646

4747
pub tcx: TyCtxt<'tcx>,
4848
pub resolver: Rc<RefCell<interface::BoxedResolver>>,
49-
/// The stack of module NodeIds up till this point
50-
pub crate_name: Option<String>,
5149
pub cstore: Lrc<CStore>,
5250
/// Later on moved into `html::render::CACHE_KEY`
5351
pub renderinfo: RefCell<RenderInfo>,
@@ -332,7 +330,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
332330
file_loader: None,
333331
diagnostic_output: DiagnosticOutput::Default,
334332
stderr: None,
335-
crate_name: crate_name.clone(),
333+
crate_name,
336334
lint_caps,
337335
};
338336

@@ -372,7 +370,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
372370
let ctxt = DocContext {
373371
tcx,
374372
resolver,
375-
crate_name,
376373
cstore: compiler.cstore().clone(),
377374
external_traits: Default::default(),
378375
active_extern_traits: Default::default(),

src/librustdoc/visit_ast.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc::hir::def::{Res, DefKind};
66
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
77
use rustc::middle::privacy::AccessLevel;
88
use rustc::util::nodemap::{FxHashSet, FxHashMap};
9+
use rustc::ty::TyCtxt;
910
use syntax::ast;
1011
use syntax::ext::base::MacroKind;
1112
use syntax::source_map::Spanned;
@@ -18,13 +19,13 @@ use crate::core;
1819
use crate::clean::{self, AttributesExt, NestedAttributesExt};
1920
use crate::doctree::*;
2021

22+
// FIXME: Should this be replaced with tcx.def_path_str?
2123
fn def_id_to_path(
22-
cx: &core::DocContext<'_>,
24+
tcx: TyCtxt<'_>,
2325
did: DefId,
24-
name: Option<String>
2526
) -> Vec<String> {
26-
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
27-
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
27+
let crate_name = tcx.crate_name(did.krate).to_string();
28+
let relative = tcx.def_path(did).data.into_iter().filter_map(|elem| {
2829
// extern blocks have an empty name
2930
let s = elem.data.to_string();
3031
if !s.is_empty() {
@@ -68,7 +69,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
6869
// We can't use the entry API, as that keeps the mutable borrow of `self` active
6970
// when we try to use `cx`.
7071
if self.exact_paths.get(&did).is_none() {
71-
let path = def_id_to_path(self.cx, did, self.cx.crate_name.clone());
72+
let path = def_id_to_path(self.cx.tcx, did);
7273
self.exact_paths.insert(did, path);
7374
}
7475
}

0 commit comments

Comments
 (0)