Skip to content

Commit b6120bf

Browse files
committed
Add type to differentiate between fake and real DefId's
1 parent 7a0f178 commit b6120bf

28 files changed

+336
-268
lines changed

compiler/rustc_hir/src/definitions.rs

-5
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ impl DefPathTable {
8787
hash
8888
}
8989

90-
/// Used by librustdoc for fake DefIds.
91-
pub fn num_def_ids(&self) -> usize {
92-
self.index_to_key.len()
93-
}
94-
9590
pub fn enumerated_keys_and_path_hashes(
9691
&self,
9792
) -> impl Iterator<Item = (DefIndex, &DefKey, &DefPathHash)> + '_ {

compiler/rustc_metadata/src/rmeta/decoder.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1885,10 +1885,6 @@ impl CrateMetadata {
18851885
self.root.hash
18861886
}
18871887

1888-
fn num_def_ids(&self) -> usize {
1889-
self.root.tables.def_keys.size()
1890-
}
1891-
18921888
fn local_def_id(&self, index: DefIndex) -> DefId {
18931889
DefId { krate: self.cnum, index }
18941890
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-4
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,6 @@ impl CStore {
461461
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
462462
}
463463

464-
pub fn num_def_ids(&self, cnum: CrateNum) -> usize {
465-
self.get_crate_data(cnum).num_def_ids()
466-
}
467-
468464
pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
469465
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
470466
}

src/librustdoc/clean/auto_trait.rs

+1-1
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: self.cx.next_def_id(item_def_id.krate),
116+
def_id: FakeDefId::new_fake(item_def_id.krate),
117117
kind: box ImplItem(Impl {
118118
span: Span::dummy(),
119119
unsafety: hir::Unsafety::Normal,

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
9797
name: None,
9898
attrs: Default::default(),
9999
visibility: Inherited,
100-
def_id: self.cx.next_def_id(impl_def_id.krate),
100+
def_id: FakeDefId::new_fake(item_def_id.krate),
101101
kind: box ImplItem(Impl {
102102
span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
103103
unsafety: hir::Unsafety::Normal,

src/librustdoc/clean/inline.rs

+4-4
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
use rustc_span::Span;
1717

18-
use crate::clean::{self, Attributes, AttributesExt, GetDefId, ToSource};
18+
use crate::clean::{self, Attributes, AttributesExt, FakeDefId, GetDefId, ToSource};
1919
use crate::core::DocContext;
2020
use crate::formats::item_type::ItemType;
2121

@@ -121,7 +121,7 @@ crate fn try_inline(
121121
};
122122

123123
let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone);
124-
cx.inlined.insert(did);
124+
cx.inlined.insert(did.into());
125125
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
126126
did,
127127
Some(name),
@@ -332,7 +332,7 @@ crate fn build_impl(
332332
attrs: Option<Attrs<'_>>,
333333
ret: &mut Vec<clean::Item>,
334334
) {
335-
if !cx.inlined.insert(did) {
335+
if !cx.inlined.insert(did.into()) {
336336
return;
337337
}
338338

@@ -470,7 +470,7 @@ fn build_module(
470470
items.push(clean::Item {
471471
name: None,
472472
attrs: box clean::Attributes::default(),
473-
def_id: cx.next_def_id(did.krate),
473+
def_id: FakeDefId::new_fake(did.krate),
474474
visibility: clean::Public,
475475
kind: box clean::ImportItem(clean::Import::new_simple(
476476
item.ident.name,

src/librustdoc/clean/mod.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ impl Clean<Generics> for hir::Generics<'_> {
533533
match param.kind {
534534
GenericParamDefKind::Lifetime => unreachable!(),
535535
GenericParamDefKind::Type { did, ref bounds, .. } => {
536-
cx.impl_trait_bounds.insert(did.into(), bounds.clone());
536+
cx.impl_trait_bounds
537+
.insert(FakeDefId::new_real(did).into(), bounds.clone());
537538
}
538539
GenericParamDefKind::Const { .. } => unreachable!(),
539540
}
@@ -614,7 +615,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
614615
.collect::<Vec<GenericParamDef>>();
615616

616617
// param index -> [(DefId of trait, associated type name, type)]
617-
let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, Symbol, Ty<'tcx>)>>::default();
618+
let mut impl_trait_proj = FxHashMap::<u32, Vec<(FakeDefId, Symbol, Ty<'tcx>)>>::default();
618619

619620
let where_predicates = preds
620621
.predicates
@@ -663,10 +664,11 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
663664
if let Some(((_, trait_did, name), rhs)) =
664665
proj.as_ref().and_then(|(lhs, rhs)| Some((lhs.projection()?, rhs)))
665666
{
666-
impl_trait_proj
667-
.entry(param_idx)
668-
.or_default()
669-
.push((trait_did, name, rhs));
667+
impl_trait_proj.entry(param_idx).or_default().push((
668+
trait_did.into(),
669+
name,
670+
rhs,
671+
));
670672
}
671673

672674
return None;
@@ -685,7 +687,13 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
685687
if let Some(proj) = impl_trait_proj.remove(&idx) {
686688
for (trait_did, name, rhs) in proj {
687689
let rhs = rhs.clean(cx);
688-
simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs);
690+
simplify::merge_bounds(
691+
cx,
692+
&mut bounds,
693+
trait_did.expect_real(),
694+
name,
695+
&rhs,
696+
);
689697
}
690698
}
691699
} else {
@@ -1175,7 +1183,8 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
11751183
if let Some(new_ty) = cx.ty_substs.get(&did).cloned() {
11761184
return new_ty;
11771185
}
1178-
if let Some(bounds) = cx.impl_trait_bounds.remove(&did.into()) {
1186+
if let Some(bounds) = cx.impl_trait_bounds.remove(&FakeDefId::new_real(did).into())
1187+
{
11791188
return ImplTrait(bounds);
11801189
}
11811190
}
@@ -2006,7 +2015,7 @@ fn clean_extern_crate(
20062015
vec![Item {
20072016
name: Some(name),
20082017
attrs: box attrs.clean(cx),
2009-
def_id: crate_def_id,
2018+
def_id: crate_def_id.into(),
20102019
visibility: krate.vis.clean(cx),
20112020
kind: box ExternCrateItem { src: orig_name },
20122021
cfg: attrs.cfg(cx.sess().diagnostic()),

0 commit comments

Comments
 (0)