Skip to content

Commit 9a27044

Browse files
committedJul 6, 2021
Auto merge of #86644 - Stupremee:replace-fakedefids-with-itemid, r=jyn514
rustdoc: Replace `FakeDefId` with new `ItemId` type Follow up from #84707 `@Manishearth` [suggested](#84707 (comment)) that there should be a new `ItemId` type that can distinguish between auto traits, normal ids, and blanket impls instead of using `FakeDefId`s. This type is introduced by this PR. There are still some `FIXME`s left, because I was unsure what the best solution for them would be. Especially the naming in general now is a bit weird right now and needs to be cleaned up. Now there are no "fake" ids so the `is_fake` method on `Item` does not really make sense and maybe the methods on `ItemId` should be renamed too? Also, we need to represent the new item ids in the JSON backend somehow.
·
1.89.01.55.0
2 parents d5a406b + a89912c commit 9a27044

20 files changed

+188
-179
lines changed
 

‎src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
113113
name: None,
114114
attrs: Default::default(),
115115
visibility: Inherited,
116-
def_id: FakeDefId::new_fake(item_def_id.krate),
116+
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
117117
kind: box ImplItem(Impl {
118118
span: Span::dummy(),
119119
unsafety: hir::Unsafety::Normal,

‎src/librustdoc/clean/blanket_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
9696
name: None,
9797
attrs: Default::default(),
9898
visibility: Inherited,
99-
def_id: FakeDefId::new_fake(item_def_id.krate),
99+
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
100100
kind: box ImplItem(Impl {
101101
span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
102102
unsafety: hir::Unsafety::Normal,

‎src/librustdoc/clean/inline.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_span::hygiene::MacroKind;
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616

1717
use crate::clean::{
18-
self, utils, Attributes, AttributesExt, FakeDefId, GetDefId, NestedAttributesExt, Type,
18+
self, utils, Attributes, AttributesExt, GetDefId, ItemId, NestedAttributesExt, Type,
1919
};
2020
use crate::core::DocContext;
2121
use crate::formats::item_type::ItemType;
@@ -483,10 +483,11 @@ fn build_module(
483483
}
484484
if let Res::PrimTy(p) = item.res {
485485
// Primitive types can't be inlined so generate an import instead.
486+
let prim_ty = clean::PrimitiveType::from(p);
486487
items.push(clean::Item {
487488
name: None,
488489
attrs: box clean::Attributes::default(),
489-
def_id: FakeDefId::new_fake(did.krate),
490+
def_id: ItemId::Primitive(prim_ty, did.krate),
490491
visibility: clean::Public,
491492
kind: box clean::ImportItem(clean::Import::new_simple(
492493
item.ident.name,
@@ -495,7 +496,7 @@ fn build_module(
495496
global: false,
496497
res: item.res,
497498
segments: vec![clean::PathSegment {
498-
name: clean::PrimitiveType::from(p).as_sym(),
499+
name: prim_ty.as_sym(),
499500
args: clean::GenericArgs::AngleBracketed {
500501
args: Vec::new(),
501502
bindings: Vec::new(),

‎src/librustdoc/clean/types.rs

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::cell::{Cell, RefCell};
1+
use std::cell::RefCell;
22
use std::default::Default;
33
use std::hash::{Hash, Hasher};
44
use std::iter::FromIterator;
@@ -48,73 +48,68 @@ use self::ItemKind::*;
4848
use self::SelfTy::*;
4949
use self::Type::*;
5050

51-
crate type FakeDefIdSet = FxHashSet<FakeDefId>;
51+
crate type ItemIdSet = FxHashSet<ItemId>;
5252

53-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
54-
crate enum FakeDefId {
55-
Real(DefId),
56-
Fake(DefIndex, CrateNum),
53+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
54+
crate enum ItemId {
55+
/// A "normal" item that uses a [`DefId`] for identification.
56+
DefId(DefId),
57+
/// Identifier that is used for auto traits.
58+
Auto { trait_: DefId, for_: DefId },
59+
/// Identifier that is used for blanket implementations.
60+
Blanket { impl_id: DefId, for_: DefId },
61+
/// Identifier for primitive types.
62+
Primitive(PrimitiveType, CrateNum),
5763
}
5864

59-
impl FakeDefId {
60-
#[cfg(parallel_compiler)]
61-
crate fn new_fake(crate: CrateNum) -> Self {
62-
unimplemented!("")
63-
}
64-
65-
#[cfg(not(parallel_compiler))]
66-
crate fn new_fake(krate: CrateNum) -> Self {
67-
thread_local!(static FAKE_DEF_ID_COUNTER: Cell<usize> = Cell::new(0));
68-
let id = FAKE_DEF_ID_COUNTER.with(|id| {
69-
let tmp = id.get();
70-
id.set(tmp + 1);
71-
tmp
72-
});
73-
Self::Fake(DefIndex::from(id), krate)
74-
}
75-
65+
impl ItemId {
7666
#[inline]
7767
crate fn is_local(self) -> bool {
7868
match self {
79-
FakeDefId::Real(id) => id.is_local(),
80-
FakeDefId::Fake(_, krate) => krate == LOCAL_CRATE,
69+
ItemId::Auto { for_: id, .. }
70+
| ItemId::Blanket { for_: id, .. }
71+
| ItemId::DefId(id) => id.is_local(),
72+
ItemId::Primitive(_, krate) => krate == LOCAL_CRATE,
8173
}
8274
}
8375

8476
#[inline]
8577
#[track_caller]
86-
crate fn expect_real(self) -> rustc_hir::def_id::DefId {
87-
self.as_real().unwrap_or_else(|| panic!("FakeDefId::expect_real: `{:?}` isn't real", self))
78+
crate fn expect_def_id(self) -> DefId {
79+
self.as_def_id()
80+
.unwrap_or_else(|| panic!("ItemId::expect_def_id: `{:?}` isn't a DefId", self))
8881
}
8982

9083
#[inline]
91-
crate fn as_real(self) -> Option<DefId> {
84+
crate fn as_def_id(self) -> Option<DefId> {
9285
match self {
93-
FakeDefId::Real(id) => Some(id),
94-
FakeDefId::Fake(_, _) => None,
86+
ItemId::DefId(id) => Some(id),
87+
_ => None,
9588
}
9689
}
9790

9891
#[inline]
9992
crate fn krate(self) -> CrateNum {
10093
match self {
101-
FakeDefId::Real(id) => id.krate,
102-
FakeDefId::Fake(_, krate) => krate,
94+
ItemId::Auto { for_: id, .. }
95+
| ItemId::Blanket { for_: id, .. }
96+
| ItemId::DefId(id) => id.krate,
97+
ItemId::Primitive(_, krate) => krate,
10398
}
10499
}
105100

106101
#[inline]
107102
crate fn index(self) -> Option<DefIndex> {
108103
match self {
109-
FakeDefId::Real(id) => Some(id.index),
110-
FakeDefId::Fake(_, _) => None,
104+
ItemId::DefId(id) => Some(id.index),
105+
_ => None,
111106
}
112107
}
113108
}
114109

115-
impl From<DefId> for FakeDefId {
110+
impl From<DefId> for ItemId {
116111
fn from(id: DefId) -> Self {
117-
Self::Real(id)
112+
Self::DefId(id)
118113
}
119114
}
120115

@@ -338,14 +333,14 @@ crate struct Item {
338333
/// Information about this item that is specific to what kind of item it is.
339334
/// E.g., struct vs enum vs function.
340335
crate kind: Box<ItemKind>,
341-
crate def_id: FakeDefId,
336+
crate def_id: ItemId,
342337

343338
crate cfg: Option<Arc<Cfg>>,
344339
}
345340

346341
// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
347342
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
348-
rustc_data_structures::static_assert_size!(Item, 48);
343+
rustc_data_structures::static_assert_size!(Item, 56);
349344

350345
crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
351346
Span::from_rustc_span(def_id.as_local().map_or_else(
@@ -359,19 +354,19 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
359354

360355
impl Item {
361356
crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<&'tcx Stability> {
362-
if self.is_fake() { None } else { tcx.lookup_stability(self.def_id.expect_real()) }
357+
self.def_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
363358
}
364359

365360
crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ConstStability> {
366-
if self.is_fake() { None } else { tcx.lookup_const_stability(self.def_id.expect_real()) }
361+
self.def_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
367362
}
368363

369364
crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {
370-
if self.is_fake() { None } else { tcx.lookup_deprecation(self.def_id.expect_real()) }
365+
self.def_id.as_def_id().and_then(|did| tcx.lookup_deprecation(did))
371366
}
372367

373368
crate fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
374-
if self.is_fake() { false } else { tcx.get_attrs(self.def_id.expect_real()).inner_docs() }
369+
self.def_id.as_def_id().map(|did| tcx.get_attrs(did).inner_docs()).unwrap_or(false)
375370
}
376371

377372
crate fn span(&self, tcx: TyCtxt<'_>) -> Span {
@@ -383,10 +378,8 @@ impl Item {
383378
kind
384379
{
385380
*span
386-
} else if self.is_fake() {
387-
Span::dummy()
388381
} else {
389-
rustc_span(self.def_id.expect_real(), tcx)
382+
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(|| Span::dummy())
390383
}
391384
}
392385

@@ -551,7 +544,7 @@ impl Item {
551544
}
552545

553546
crate fn is_crate(&self) -> bool {
554-
self.is_mod() && self.def_id.as_real().map_or(false, |did| did.index == CRATE_DEF_INDEX)
547+
self.is_mod() && self.def_id.as_def_id().map_or(false, |did| did.index == CRATE_DEF_INDEX)
555548
}
556549
crate fn is_mod(&self) -> bool {
557550
self.type_() == ItemType::Module
@@ -662,10 +655,6 @@ impl Item {
662655
_ => false,
663656
}
664657
}
665-
666-
crate fn is_fake(&self) -> bool {
667-
matches!(self.def_id, FakeDefId::Fake(_, _))
668-
}
669658
}
670659

671660
#[derive(Clone, Debug)]

‎src/librustdoc/core.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::mem;
3030
use std::rc::Rc;
3131

3232
use crate::clean::inline::build_external_trait;
33-
use crate::clean::{self, FakeDefId, TraitWithExtraInfo};
33+
use crate::clean::{self, ItemId, TraitWithExtraInfo};
3434
use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
3535
use crate::formats::cache::Cache;
3636
use crate::passes::{self, Condition::*, ConditionalPass};
@@ -78,7 +78,7 @@ crate struct DocContext<'tcx> {
7878
/// This same cache is used throughout rustdoc, including in [`crate::html::render`].
7979
crate cache: Cache,
8080
/// Used by [`clean::inline`] to tell if an item has already been inlined.
81-
crate inlined: FxHashSet<FakeDefId>,
81+
crate inlined: FxHashSet<ItemId>,
8282
/// Used by `calculate_doc_coverage`.
8383
crate output_format: OutputFormat,
8484
}
@@ -128,12 +128,13 @@ impl<'tcx> DocContext<'tcx> {
128128

129129
/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
130130
/// (This avoids a slice-index-out-of-bounds panic.)
131-
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: FakeDefId) -> Option<HirId> {
131+
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: ItemId) -> Option<HirId> {
132132
match def_id {
133-
FakeDefId::Real(real_id) => {
133+
ItemId::DefId(real_id) => {
134134
real_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
135135
}
136-
FakeDefId::Fake(_, _) => None,
136+
// FIXME: Can this be `Some` for `Auto` or `Blanket`?
137+
_ => None,
137138
}
138139
}
139140
}

‎src/librustdoc/formats/cache.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::middle::privacy::AccessLevels;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_span::symbol::sym;
1010

11-
use crate::clean::{self, FakeDefId, GetDefId};
11+
use crate::clean::{self, GetDefId, ItemId};
1212
use crate::fold::DocFolder;
1313
use crate::formats::item_type::ItemType;
1414
use crate::formats::Impl;
@@ -122,7 +122,7 @@ crate struct Cache {
122122
/// All intra-doc links resolved so far.
123123
///
124124
/// Links are indexed by the DefId of the item they document.
125-
crate intra_doc_links: BTreeMap<FakeDefId, Vec<clean::ItemLink>>,
125+
crate intra_doc_links: FxHashMap<ItemId, Vec<clean::ItemLink>>,
126126
}
127127

128128
/// This struct is used to wrap the `cache` and `tcx` in order to run `DocFolder`.
@@ -215,7 +215,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
215215
// Propagate a trait method's documentation to all implementors of the
216216
// trait.
217217
if let clean::TraitItem(ref t) = *item.kind {
218-
self.cache.traits.entry(item.def_id.expect_real()).or_insert_with(|| {
218+
self.cache.traits.entry(item.def_id.expect_def_id()).or_insert_with(|| {
219219
clean::TraitWithExtraInfo {
220220
trait_: t.clone(),
221221
is_notable: item.attrs.has_doc_flag(sym::notable_trait),
@@ -348,11 +348,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
348348
// `public_items` map, so we can skip inserting into the
349349
// paths map if there was already an entry present and we're
350350
// not a public item.
351-
if !self.cache.paths.contains_key(&item.def_id.expect_real())
352-
|| self.cache.access_levels.is_public(item.def_id.expect_real())
351+
if !self.cache.paths.contains_key(&item.def_id.expect_def_id())
352+
|| self.cache.access_levels.is_public(item.def_id.expect_def_id())
353353
{
354354
self.cache.paths.insert(
355-
item.def_id.expect_real(),
355+
item.def_id.expect_def_id(),
356356
(self.cache.stack.clone(), item.type_()),
357357
);
358358
}
@@ -361,7 +361,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
361361
clean::PrimitiveItem(..) => {
362362
self.cache
363363
.paths
364-
.insert(item.def_id.expect_real(), (self.cache.stack.clone(), item.type_()));
364+
.insert(item.def_id.expect_def_id(), (self.cache.stack.clone(), item.type_()));
365365
}
366366

367367
clean::ExternCrateItem { .. }
@@ -391,7 +391,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
391391
| clean::StructItem(..)
392392
| clean::UnionItem(..)
393393
| clean::VariantItem(..) => {
394-
self.cache.parent_stack.push(item.def_id.expect_real());
394+
self.cache.parent_stack.push(item.def_id.expect_def_id());
395395
self.cache.parent_is_trait_impl = false;
396396
true
397397
}

‎src/librustdoc/html/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::def_id::CRATE_DEF_INDEX;
1919
use rustc_target::spec::abi::Abi;
2020

2121
use crate::clean::{
22-
self, utils::find_nearest_parent_module, ExternalCrate, FakeDefId, GetDefId, PrimitiveType,
22+
self, utils::find_nearest_parent_module, ExternalCrate, GetDefId, ItemId, PrimitiveType,
2323
};
2424
use crate::formats::item_type::ItemType;
2525
use crate::html::escape::Escape;
@@ -1181,7 +1181,7 @@ impl clean::FnDecl {
11811181
impl clean::Visibility {
11821182
crate fn print_with_space<'a, 'tcx: 'a>(
11831183
self,
1184-
item_did: FakeDefId,
1184+
item_did: ItemId,
11851185
cx: &'a Context<'tcx>,
11861186
) -> impl fmt::Display + 'a + Captures<'tcx> {
11871187
let to_print = match self {
@@ -1191,7 +1191,7 @@ impl clean::Visibility {
11911191
// FIXME(camelid): This may not work correctly if `item_did` is a module.
11921192
// However, rustdoc currently never displays a module's
11931193
// visibility, so it shouldn't matter.
1194-
let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_real());
1194+
let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_def_id());
11951195

11961196
if vis_did.index == CRATE_DEF_INDEX {
11971197
"pub(crate) ".to_owned()

‎src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'tcx> Context<'tcx> {
230230
&self.shared.style_files,
231231
)
232232
} else {
233-
if let Some(&(ref names, ty)) = self.cache.paths.get(&it.def_id.expect_real()) {
233+
if let Some(&(ref names, ty)) = self.cache.paths.get(&it.def_id.expect_def_id()) {
234234
let mut path = String::new();
235235
for name in &names[..names.len() - 1] {
236236
path.push_str(name);

‎src/librustdoc/html/render/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
5353
use serde::ser::SerializeSeq;
5454
use serde::{Serialize, Serializer};
5555

56-
use crate::clean::{self, FakeDefId, GetDefId, RenderedLink, SelfTy};
56+
use crate::clean::{self, GetDefId, ItemId, RenderedLink, SelfTy};
5757
use crate::docfs::PathError;
5858
use crate::error::Error;
5959
use crate::formats::cache::Cache;
@@ -735,7 +735,7 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink<'_>, cx: &Context<'_>)
735735
AssocItemLink::Anchor(Some(ref id)) => format!("#{}", id),
736736
AssocItemLink::Anchor(None) => anchor,
737737
AssocItemLink::GotoSource(did, _) => {
738-
href(did.expect_real(), cx).map(|p| format!("{}{}", p.0, anchor)).unwrap_or(anchor)
738+
href(did.expect_def_id(), cx).map(|p| format!("{}{}", p.0, anchor)).unwrap_or(anchor)
739739
}
740740
}
741741
}
@@ -867,7 +867,7 @@ fn render_assoc_item(
867867
ItemType::TyMethod
868868
};
869869

870-
href(did.expect_real(), cx)
870+
href(did.expect_def_id(), cx)
871871
.map(|p| format!("{}#{}.{}", p.0, ty, name))
872872
.unwrap_or_else(|| format!("#{}.{}", ty, name))
873873
}
@@ -987,7 +987,7 @@ fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item) {
987987
#[derive(Copy, Clone)]
988988
enum AssocItemLink<'a> {
989989
Anchor(Option<&'a str>),
990-
GotoSource(FakeDefId, &'a FxHashSet<Symbol>),
990+
GotoSource(ItemId, &'a FxHashSet<Symbol>),
991991
}
992992

993993
impl<'a> AssocItemLink<'a> {
@@ -1819,7 +1819,7 @@ fn small_url_encode(s: String) -> String {
18191819
}
18201820

18211821
fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
1822-
let did = it.def_id.expect_real();
1822+
let did = it.def_id.expect_def_id();
18231823
if let Some(v) = cx.cache.impls.get(&did) {
18241824
let mut used_links = FxHashSet::default();
18251825
let cache = cx.cache();
@@ -2109,7 +2109,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21092109
"</div>",
21102110
);
21112111

2112-
if let Some(implementors) = cx.cache.implementors.get(&it.def_id.expect_real()) {
2112+
if let Some(implementors) = cx.cache.implementors.get(&it.def_id.expect_def_id()) {
21132113
let cache = cx.cache();
21142114
let mut res = implementors
21152115
.iter()

‎src/librustdoc/html/render/print_item.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
289289
w,
290290
"<div class=\"item-left\"><code>{}extern crate {} as {};",
291291
myitem.visibility.print_with_space(myitem.def_id, cx),
292-
anchor(myitem.def_id.expect_real(), &*src.as_str(), cx),
292+
anchor(myitem.def_id.expect_def_id(), &*src.as_str(), cx),
293293
myitem.name.as_ref().unwrap(),
294294
),
295295
None => write!(
296296
w,
297297
"<div class=\"item-left\"><code>{}extern crate {};",
298298
myitem.visibility.print_with_space(myitem.def_id, cx),
299299
anchor(
300-
myitem.def_id.expect_real(),
300+
myitem.def_id.expect_def_id(),
301301
&*myitem.name.as_ref().unwrap().as_str(),
302302
cx
303303
),
@@ -669,9 +669,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
669669
}
670670

671671
// If there are methods directly on this trait object, render them here.
672-
render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All);
672+
render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All);
673673

674-
if let Some(implementors) = cx.cache.implementors.get(&it.def_id.expect_real()) {
674+
if let Some(implementors) = cx.cache.implementors.get(&it.def_id.expect_def_id()) {
675675
// The DefId is for the first Type found with that name. The bool is
676676
// if any Types with the same name but different DefId have been found.
677677
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
@@ -787,7 +787,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
787787
path = if it.def_id.is_local() {
788788
cx.current.join("/")
789789
} else {
790-
let (ref path, _) = cx.cache.external_paths[&it.def_id.expect_real()];
790+
let (ref path, _) = cx.cache.external_paths[&it.def_id.expect_def_id()];
791791
path[..path.len() - 1].join("/")
792792
},
793793
ty = it.type_(),
@@ -813,7 +813,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
813813
// won't be visible anywhere in the docs. It would be nice to also show
814814
// associated items from the aliased type (see discussion in #32077), but
815815
// we need #14072 to make sense of the generics.
816-
render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All)
816+
render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All)
817817
}
818818

819819
fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) {
@@ -834,7 +834,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
834834
// won't be visible anywhere in the docs. It would be nice to also show
835835
// associated items from the aliased type (see discussion in #32077), but
836836
// we need #14072 to make sense of the generics.
837-
render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All)
837+
render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All)
838838
}
839839

840840
fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
@@ -851,7 +851,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
851851

852852
document(w, cx, it, None);
853853

854-
let def_id = it.def_id.expect_real();
854+
let def_id = it.def_id.expect_def_id();
855855
// Render any items associated directly to this alias, as otherwise they
856856
// won't be visible anywhere in the docs. It would be nice to also show
857857
// associated items from the aliased type (see discussion in #32077), but
@@ -903,7 +903,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
903903
document(w, cx, field, Some(it));
904904
}
905905
}
906-
let def_id = it.def_id.expect_real();
906+
let def_id = it.def_id.expect_def_id();
907907
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);
908908
document_type_layout(w, cx, def_id);
909909
}
@@ -1041,7 +1041,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
10411041
}
10421042
}
10431043
}
1044-
let def_id = it.def_id.expect_real();
1044+
let def_id = it.def_id.expect_def_id();
10451045
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);
10461046
document_type_layout(w, cx, def_id);
10471047
}
@@ -1093,7 +1093,7 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean
10931093

10941094
fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
10951095
document(w, cx, it, None);
1096-
render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All)
1096+
render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All)
10971097
}
10981098

10991099
fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::Constant) {
@@ -1182,7 +1182,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
11821182
}
11831183
}
11841184
}
1185-
let def_id = it.def_id.expect_real();
1185+
let def_id = it.def_id.expect_def_id();
11861186
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);
11871187
document_type_layout(w, cx, def_id);
11881188
}
@@ -1213,7 +1213,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
12131213

12141214
document(w, cx, it, None);
12151215

1216-
render_assoc_items(w, cx, it, it.def_id.expect_real(), AssocItemRender::All)
1216+
render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All)
12171217
}
12181218

12191219
fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {

‎src/librustdoc/json/conversions.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
#![allow(rustc::default_hash_types)]
66

77
use std::convert::From;
8+
use std::fmt;
89

910
use rustc_ast::ast;
10-
use rustc_hir::def::CtorKind;
11+
use rustc_hir::{def::CtorKind, def_id::DefId};
1112
use rustc_middle::ty::TyCtxt;
1213
use rustc_span::def_id::CRATE_DEF_INDEX;
1314
use rustc_span::Pos;
1415

1516
use rustdoc_json_types::*;
1617

1718
use crate::clean::utils::print_const_expr;
18-
use crate::clean::{self, FakeDefId};
19+
use crate::clean::{self, ItemId};
1920
use crate::formats::item_type::ItemType;
2021
use crate::json::JsonRenderer;
2122
use std::collections::HashSet;
@@ -30,7 +31,7 @@ impl JsonRenderer<'_> {
3031
.into_iter()
3132
.flatten()
3233
.filter_map(|clean::ItemLink { link, did, .. }| {
33-
did.map(|did| (link.clone(), from_def_id(did.into())))
34+
did.map(|did| (link.clone(), from_item_id(did.into())))
3435
})
3536
.collect();
3637
let docs = item.attrs.collapsed_doc_value();
@@ -47,7 +48,7 @@ impl JsonRenderer<'_> {
4748
_ => from_clean_item(item, self.tcx),
4849
};
4950
Some(Item {
50-
id: from_def_id(def_id),
51+
id: from_item_id(def_id),
5152
crate_id: def_id.krate().as_u32(),
5253
name: name.map(|sym| sym.to_string()),
5354
span: self.convert_span(span),
@@ -86,7 +87,7 @@ impl JsonRenderer<'_> {
8687
Inherited => Visibility::Default,
8788
Restricted(did) if did.index == CRATE_DEF_INDEX => Visibility::Crate,
8889
Restricted(did) => Visibility::Restricted {
89-
parent: from_def_id(did.into()),
90+
parent: from_item_id(did.into()),
9091
path: self.tcx.def_path(did).to_string_no_crate_verbose(),
9192
},
9293
}
@@ -170,12 +171,24 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
170171
}
171172
}
172173

173-
crate fn from_def_id(did: FakeDefId) -> Id {
174+
crate fn from_item_id(did: ItemId) -> Id {
175+
struct DisplayDefId(DefId);
176+
177+
impl fmt::Display for DisplayDefId {
178+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179+
write!(f, "{}:{}", self.0.krate.as_u32(), u32::from(self.0.index))
180+
}
181+
}
182+
174183
match did {
175-
FakeDefId::Real(did) => Id(format!("{}:{}", did.krate.as_u32(), u32::from(did.index))),
176-
// We need to differentiate real and fake ids, because the indices might overlap for fake
177-
// and real DefId's, which would cause two different Id's treated as they were the same.
178-
FakeDefId::Fake(idx, krate) => Id(format!("F{}:{}", krate.as_u32(), u32::from(idx))),
184+
ItemId::DefId(did) => Id(format!("{}", DisplayDefId(did))),
185+
ItemId::Blanket { for_, impl_id } => {
186+
Id(format!("b:{}-{}", DisplayDefId(impl_id), DisplayDefId(for_)))
187+
}
188+
ItemId::Auto { for_, trait_ } => {
189+
Id(format!("a:{}-{}", DisplayDefId(trait_), DisplayDefId(for_)))
190+
}
191+
ItemId::Primitive(ty, krate) => Id(format!("p:{}:{}", krate.as_u32(), ty.as_sym())),
179192
}
180193
}
181194

@@ -375,7 +388,7 @@ impl FromWithTcx<clean::Type> for Type {
375388
match ty {
376389
ResolvedPath { path, did, is_generic: _ } => Type::ResolvedPath {
377390
name: path.whole_name(),
378-
id: from_def_id(did.into()),
391+
id: from_item_id(did.into()),
379392
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
380393
param_names: Vec::new(),
381394
},
@@ -387,7 +400,7 @@ impl FromWithTcx<clean::Type> for Type {
387400

388401
Type::ResolvedPath {
389402
name: path.whole_name(),
390-
id: from_def_id(id.into()),
403+
id: from_item_id(id.into()),
391404
args: path
392405
.segments
393406
.last()
@@ -568,13 +581,13 @@ impl FromWithTcx<clean::Import> for Import {
568581
Simple(s) => Import {
569582
source: import.source.path.whole_name(),
570583
name: s.to_string(),
571-
id: import.source.did.map(FakeDefId::from).map(from_def_id),
584+
id: import.source.did.map(ItemId::from).map(from_item_id),
572585
glob: false,
573586
},
574587
Glob => Import {
575588
source: import.source.path.whole_name(),
576589
name: import.source.path.last_name().to_string(),
577-
id: import.source.did.map(FakeDefId::from).map(from_def_id),
590+
id: import.source.did.map(ItemId::from).map(from_item_id),
578591
glob: true,
579592
},
580593
}
@@ -668,5 +681,5 @@ impl FromWithTcx<ItemType> for ItemKind {
668681
}
669682

670683
fn ids(items: impl IntoIterator<Item = clean::Item>) -> Vec<Id> {
671-
items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_def_id(i.def_id)).collect()
684+
items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_item_id(i.def_id)).collect()
672685
}

‎src/librustdoc/json/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::error::Error;
2525
use crate::formats::cache::Cache;
2626
use crate::formats::FormatRenderer;
2727
use crate::html::render::cache::ExternalLocation;
28-
use crate::json::conversions::{from_def_id, IntoWithTcx};
28+
use crate::json::conversions::{from_item_id, IntoWithTcx};
2929

3030
#[derive(Clone)]
3131
crate struct JsonRenderer<'tcx> {
@@ -53,7 +53,7 @@ impl JsonRenderer<'tcx> {
5353
.map(|i| {
5454
let item = &i.impl_item;
5555
self.item(item.clone()).unwrap();
56-
from_def_id(item.def_id)
56+
from_item_id(item.def_id)
5757
})
5858
.collect()
5959
})
@@ -71,7 +71,7 @@ impl JsonRenderer<'tcx> {
7171
let item = &i.impl_item;
7272
if item.def_id.is_local() {
7373
self.item(item.clone()).unwrap();
74-
Some(from_def_id(item.def_id))
74+
Some(from_item_id(item.def_id))
7575
} else {
7676
None
7777
}
@@ -91,9 +91,9 @@ impl JsonRenderer<'tcx> {
9191
let trait_item = &trait_item.trait_;
9292
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
9393
Some((
94-
from_def_id(id.into()),
94+
from_item_id(id.into()),
9595
types::Item {
96-
id: from_def_id(id.into()),
96+
id: from_item_id(id.into()),
9797
crate_id: id.krate.as_u32(),
9898
name: self
9999
.cache
@@ -164,13 +164,13 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
164164
let id = item.def_id;
165165
if let Some(mut new_item) = self.convert_item(item) {
166166
if let types::ItemEnum::Trait(ref mut t) = new_item.inner {
167-
t.implementors = self.get_trait_implementors(id.expect_real())
167+
t.implementors = self.get_trait_implementors(id.expect_def_id())
168168
} else if let types::ItemEnum::Struct(ref mut s) = new_item.inner {
169-
s.impls = self.get_impls(id.expect_real())
169+
s.impls = self.get_impls(id.expect_def_id())
170170
} else if let types::ItemEnum::Enum(ref mut e) = new_item.inner {
171-
e.impls = self.get_impls(id.expect_real())
171+
e.impls = self.get_impls(id.expect_def_id())
172172
}
173-
let removed = self.index.borrow_mut().insert(from_def_id(id), new_item.clone());
173+
let removed = self.index.borrow_mut().insert(from_item_id(id), new_item.clone());
174174

175175
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
176176
// to make sure the items are unique. The main place this happens is when an item, is
@@ -207,7 +207,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
207207
.chain(self.cache.external_paths.clone().into_iter())
208208
.map(|(k, (path, kind))| {
209209
(
210-
from_def_id(k.into()),
210+
from_item_id(k.into()),
211211
types::ItemSummary {
212212
crate_id: k.krate.as_u32(),
213213
path,

‎src/librustdoc/passes/calculate_doc_coverage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
213213

214214
let filename = i.span(self.ctx.tcx).filename(self.ctx.sess());
215215
let has_doc_example = tests.found_tests != 0;
216-
// The `expect_real()` should be okay because `local_def_id_to_hir_id`
216+
// The `expect_def_id()` should be okay because `local_def_id_to_hir_id`
217217
// would presumably panic if a fake `DefIndex` were passed.
218218
let hir_id = self
219219
.ctx
220220
.tcx
221221
.hir()
222-
.local_def_id_to_hir_id(i.def_id.expect_real().expect_local());
222+
.local_def_id_to_hir_id(i.def_id.expect_def_id().expect_local());
223223
let (level, source) = self.ctx.tcx.lint_level_at_node(MISSING_DOCS, hir_id);
224224
// `missing_docs` is allow-by-default, so don't treat this as ignoring the item
225225
// unless the user had an explicit `allow`

‎src/librustdoc/passes/check_code_block_syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
5353
return;
5454
}
5555

56-
let local_id = match item.def_id.as_real().and_then(|x| x.as_local()) {
56+
let local_id = match item.def_id.as_def_id().and_then(|x| x.as_local()) {
5757
Some(id) => id,
5858
// We don't need to check the syntax for other crates so returning
5959
// without doing anything should not be a problem.
@@ -137,7 +137,7 @@ impl<'a, 'tcx> DocFolder for SyntaxChecker<'a, 'tcx> {
137137
let sp = item.attr_span(self.cx.tcx);
138138
let extra = crate::html::markdown::ExtraInfo::new_did(
139139
self.cx.tcx,
140-
item.def_id.expect_real(),
140+
item.def_id.expect_def_id(),
141141
sp,
142142
);
143143
for code_block in markdown::rust_code_blocks(&dox, &extra) {

‎src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -830,49 +830,48 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
830830
fn fold_item(&mut self, item: Item) -> Option<Item> {
831831
use rustc_middle::ty::DefIdTree;
832832

833-
let parent_node = if item.is_fake() {
834-
None
835-
} else {
836-
find_nearest_parent_module(self.cx.tcx, item.def_id.expect_real())
837-
};
838-
833+
let parent_node =
834+
item.def_id.as_def_id().and_then(|did| find_nearest_parent_module(self.cx.tcx, did));
839835
if parent_node.is_some() {
840836
trace!("got parent node for {:?} {:?}, id {:?}", item.type_(), item.name, item.def_id);
841837
}
842838

843839
// find item's parent to resolve `Self` in item's docs below
844840
debug!("looking for the `Self` type");
845-
let self_id = if item.is_fake() {
846-
None
847-
// Checking if the item is a field in an enum variant
848-
} else if (matches!(self.cx.tcx.def_kind(item.def_id.expect_real()), DefKind::Field)
849-
&& matches!(
850-
self.cx.tcx.def_kind(self.cx.tcx.parent(item.def_id.expect_real()).unwrap()),
851-
DefKind::Variant
852-
))
853-
{
854-
self.cx
855-
.tcx
856-
.parent(item.def_id.expect_real())
857-
.and_then(|item_id| self.cx.tcx.parent(item_id))
858-
} else if matches!(
859-
self.cx.tcx.def_kind(item.def_id.expect_real()),
860-
DefKind::AssocConst
861-
| DefKind::AssocFn
862-
| DefKind::AssocTy
863-
| DefKind::Variant
864-
| DefKind::Field
865-
) {
866-
self.cx.tcx.parent(item.def_id.expect_real())
867-
// HACK(jynelson): `clean` marks associated types as `TypedefItem`, not as `AssocTypeItem`.
868-
// Fixing this breaks `fn render_deref_methods`.
869-
// As a workaround, see if the parent of the item is an `impl`; if so this must be an associated item,
870-
// regardless of what rustdoc wants to call it.
871-
} else if let Some(parent) = self.cx.tcx.parent(item.def_id.expect_real()) {
872-
let parent_kind = self.cx.tcx.def_kind(parent);
873-
Some(if parent_kind == DefKind::Impl { parent } else { item.def_id.expect_real() })
874-
} else {
875-
Some(item.def_id.expect_real())
841+
let self_id = match item.def_id.as_def_id() {
842+
None => None,
843+
Some(did)
844+
if (matches!(self.cx.tcx.def_kind(did), DefKind::Field)
845+
&& matches!(
846+
self.cx.tcx.def_kind(self.cx.tcx.parent(did).unwrap()),
847+
DefKind::Variant
848+
)) =>
849+
{
850+
self.cx.tcx.parent(did).and_then(|item_id| self.cx.tcx.parent(item_id))
851+
}
852+
Some(did)
853+
if matches!(
854+
self.cx.tcx.def_kind(did),
855+
DefKind::AssocConst
856+
| DefKind::AssocFn
857+
| DefKind::AssocTy
858+
| DefKind::Variant
859+
| DefKind::Field
860+
) =>
861+
{
862+
self.cx.tcx.parent(did)
863+
}
864+
Some(did) => match self.cx.tcx.parent(did) {
865+
// HACK(jynelson): `clean` marks associated types as `TypedefItem`, not as `AssocTypeItem`.
866+
// Fixing this breaks `fn render_deref_methods`.
867+
// As a workaround, see if the parent of the item is an `impl`; if so this must be an associated item,
868+
// regardless of what rustdoc wants to call it.
869+
Some(parent) => {
870+
let parent_kind = self.cx.tcx.def_kind(parent);
871+
Some(if parent_kind == DefKind::Impl { parent } else { did })
872+
}
873+
None => Some(did),
874+
},
876875
};
877876

878877
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
@@ -897,7 +896,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
897896
let inner_docs = item.inner_docs(self.cx.tcx);
898897

899898
if item.is_mod() && inner_docs {
900-
self.mod_ids.push(item.def_id.expect_real());
899+
self.mod_ids.push(item.def_id.expect_def_id());
901900
}
902901

903902
// We want to resolve in the lexical scope of the documentation.
@@ -924,7 +923,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
924923

925924
Some(if item.is_mod() {
926925
if !inner_docs {
927-
self.mod_ids.push(item.def_id.expect_real());
926+
self.mod_ids.push(item.def_id.expect_def_id());
928927
}
929928

930929
let ret = self.fold_item_recur(item);
@@ -1235,10 +1234,10 @@ impl LinkCollector<'_, '_> {
12351234
// item can be non-local e.g. when using #[doc(primitive = "pointer")]
12361235
if let Some((src_id, dst_id)) = id
12371236
.as_local()
1238-
// The `expect_real()` should be okay because `local_def_id_to_hir_id`
1237+
// The `expect_def_id()` should be okay because `local_def_id_to_hir_id`
12391238
// would presumably panic if a fake `DefIndex` were passed.
12401239
.and_then(|dst_id| {
1241-
item.def_id.expect_real().as_local().map(|src_id| (src_id, dst_id))
1240+
item.def_id.expect_def_id().as_local().map(|src_id| (src_id, dst_id))
12421241
})
12431242
{
12441243
let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id);

‎src/librustdoc/passes/collect_trait_impls.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ impl<'a, 'tcx> DocFolder for SyntheticImplCollector<'a, 'tcx> {
136136
fn fold_item(&mut self, i: Item) -> Option<Item> {
137137
if i.is_struct() || i.is_enum() || i.is_union() {
138138
// FIXME(eddyb) is this `doc(hidden)` check needed?
139-
if !self.cx.tcx.get_attrs(i.def_id.expect_real()).lists(sym::doc).has_word(sym::hidden)
139+
if !self
140+
.cx
141+
.tcx
142+
.get_attrs(i.def_id.expect_def_id())
143+
.lists(sym::doc)
144+
.has_word(sym::hidden)
140145
{
141146
self.impls
142-
.extend(get_auto_trait_and_blanket_impls(self.cx, i.def_id.expect_real()));
147+
.extend(get_auto_trait_and_blanket_impls(self.cx, i.def_id.expect_def_id()));
143148
}
144149
}
145150

@@ -149,7 +154,7 @@ impl<'a, 'tcx> DocFolder for SyntheticImplCollector<'a, 'tcx> {
149154

150155
#[derive(Default)]
151156
struct ItemCollector {
152-
items: FxHashSet<FakeDefId>,
157+
items: FxHashSet<ItemId>,
153158
}
154159

155160
impl ItemCollector {
@@ -168,7 +173,7 @@ impl DocFolder for ItemCollector {
168173

169174
struct BadImplStripper {
170175
prims: FxHashSet<PrimitiveType>,
171-
items: FxHashSet<FakeDefId>,
176+
items: FxHashSet<ItemId>,
172177
}
173178

174179
impl BadImplStripper {
@@ -185,7 +190,7 @@ impl BadImplStripper {
185190
}
186191
}
187192

188-
fn keep_impl_with_def_id(&self, did: FakeDefId) -> bool {
193+
fn keep_impl_with_def_id(&self, did: ItemId) -> bool {
189194
self.items.contains(&did)
190195
}
191196
}

‎src/librustdoc/passes/doc_test_lints.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl crate::doctest::Tester for Tests {
5353
}
5454

5555
crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool {
56-
if !cx.cache.access_levels.is_public(item.def_id.expect_real())
56+
if !cx.cache.access_levels.is_public(item.def_id.expect_def_id())
5757
|| matches!(
5858
*item.kind,
5959
clean::StructFieldItem(_)
@@ -71,9 +71,9 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
7171
{
7272
return false;
7373
}
74-
// The `expect_real()` should be okay because `local_def_id_to_hir_id`
74+
// The `expect_def_id()` should be okay because `local_def_id_to_hir_id`
7575
// would presumably panic if a fake `DefIndex` were passed.
76-
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_real().expect_local());
76+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_def_id().expect_local());
7777
if cx.tcx.hir().attrs(hir_id).lists(sym::doc).has_word(sym::hidden)
7878
|| inherits_doc_hidden(cx.tcx, hir_id)
7979
{
@@ -107,7 +107,8 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
107107
|lint| lint.build("missing code example in this documentation").emit(),
108108
);
109109
}
110-
} else if tests.found_tests > 0 && !cx.cache.access_levels.is_public(item.def_id.expect_real())
110+
} else if tests.found_tests > 0
111+
&& !cx.cache.access_levels.is_public(item.def_id.expect_def_id())
111112
{
112113
cx.tcx.struct_span_lint_hir(
113114
crate::lint::PRIVATE_DOC_TESTS,

‎src/librustdoc/passes/strip_hidden.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_span::symbol::sym;
22
use std::mem;
33

44
use crate::clean;
5-
use crate::clean::{FakeDefIdSet, Item, NestedAttributesExt};
5+
use crate::clean::{Item, ItemIdSet, NestedAttributesExt};
66
use crate::core::DocContext;
77
use crate::fold::{strip_item, DocFolder};
88
use crate::passes::{ImplStripper, Pass};
@@ -15,7 +15,7 @@ crate const STRIP_HIDDEN: Pass = Pass {
1515

1616
/// Strip items marked `#[doc(hidden)]`
1717
crate fn strip_hidden(krate: clean::Crate, _: &mut DocContext<'_>) -> clean::Crate {
18-
let mut retained = FakeDefIdSet::default();
18+
let mut retained = ItemIdSet::default();
1919

2020
// strip all #[doc(hidden)] items
2121
let krate = {
@@ -29,7 +29,7 @@ crate fn strip_hidden(krate: clean::Crate, _: &mut DocContext<'_>) -> clean::Cra
2929
}
3030

3131
struct Stripper<'a> {
32-
retained: &'a mut FakeDefIdSet,
32+
retained: &'a mut ItemIdSet,
3333
update_retained: bool,
3434
}
3535

‎src/librustdoc/passes/strip_private.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::clean::{self, FakeDefIdSet};
1+
use crate::clean::{self, ItemIdSet};
22
use crate::core::DocContext;
33
use crate::fold::DocFolder;
44
use crate::passes::{ImplStripper, ImportStripper, Pass, Stripper};
@@ -14,7 +14,7 @@ crate const STRIP_PRIVATE: Pass = Pass {
1414
/// crate, specified by the `xcrate` flag.
1515
crate fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
1616
// This stripper collects all *retained* nodes.
17-
let mut retained = FakeDefIdSet::default();
17+
let mut retained = ItemIdSet::default();
1818

1919
// strip all private items
2020
{

‎src/librustdoc/passes/stripper.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use rustc_hir::def_id::DefId;
22
use rustc_middle::middle::privacy::AccessLevels;
33
use std::mem;
44

5-
use crate::clean::{self, FakeDefIdSet, GetDefId, Item};
5+
use crate::clean::{self, GetDefId, Item, ItemIdSet};
66
use crate::fold::{strip_item, DocFolder};
77

88
crate struct Stripper<'a> {
9-
crate retained: &'a mut FakeDefIdSet,
9+
crate retained: &'a mut ItemIdSet,
1010
crate access_levels: &'a AccessLevels<DefId>,
1111
crate update_retained: bool,
1212
}
@@ -42,7 +42,7 @@ impl<'a> DocFolder for Stripper<'a> {
4242
| clean::TraitAliasItem(..)
4343
| clean::ForeignTypeItem => {
4444
if i.def_id.is_local() {
45-
if !self.access_levels.is_exported(i.def_id.expect_real()) {
45+
if !self.access_levels.is_exported(i.def_id.expect_def_id()) {
4646
debug!("Stripper: stripping {:?} {:?}", i.type_(), i.name);
4747
return None;
4848
}
@@ -116,7 +116,7 @@ impl<'a> DocFolder for Stripper<'a> {
116116

117117
/// This stripper discards all impls which reference stripped items
118118
crate struct ImplStripper<'a> {
119-
crate retained: &'a FakeDefIdSet,
119+
crate retained: &'a ItemIdSet,
120120
}
121121

122122
impl<'a> DocFolder for ImplStripper<'a> {

0 commit comments

Comments
 (0)
Please sign in to comment.