Skip to content

Commit

Permalink
Auto merge of rust-lang#84707 - Stupremee:remove-fake-defids-in-rustd…
Browse files Browse the repository at this point in the history
…oc, r=jyn514,GuillaumeGomez

Get rid of fake `DefId`s in rustdoc

Right now there are *many* errors left, but I wanted to show the current state since all that is left to do is fixing the errors.

Resolves rust-lang#83183

r? `@jyn514`
  • Loading branch information
bors committed May 4, 2021
2 parents 8bf0bd9 + b6120bf commit ae8b84b
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 268 deletions.
5 changes: 0 additions & 5 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ impl DefPathTable {
hash
}

/// Used by librustdoc for fake DefIds.
pub fn num_def_ids(&self) -> usize {
self.index_to_key.len()
}

pub fn enumerated_keys_and_path_hashes(
&self,
) -> impl Iterator<Item = (DefIndex, &DefKey, &DefPathHash)> + '_ {
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,10 +1885,6 @@ impl CrateMetadata {
self.root.hash
}

fn num_def_ids(&self) -> usize {
self.root.tables.def_keys.size()
}

fn local_def_id(&self, index: DefIndex) -> DefId {
DefId { krate: self.cnum, index }
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,6 @@ impl CStore {
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
}

pub fn num_def_ids(&self, cnum: CrateNum) -> usize {
self.get_crate_data(cnum).num_def_ids()
}

pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: self.cx.next_def_id(item_def_id.krate),
def_id: FakeDefId::new_fake(item_def_id.krate),
kind: box ImplItem(Impl {
span: Span::dummy(),
unsafety: hir::Unsafety::Normal,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: self.cx.next_def_id(impl_def_id.krate),
def_id: FakeDefId::new_fake(item_def_id.krate),
kind: box ImplItem(Impl {
span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
unsafety: hir::Unsafety::Normal,
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;

use crate::clean::{self, Attributes, AttributesExt, GetDefId, ToSource};
use crate::clean::{self, Attributes, AttributesExt, FakeDefId, GetDefId, ToSource};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;

Expand Down Expand Up @@ -121,7 +121,7 @@ crate fn try_inline(
};

let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone);
cx.inlined.insert(did);
cx.inlined.insert(did.into());
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
did,
Some(name),
Expand Down Expand Up @@ -332,7 +332,7 @@ crate fn build_impl(
attrs: Option<Attrs<'_>>,
ret: &mut Vec<clean::Item>,
) {
if !cx.inlined.insert(did) {
if !cx.inlined.insert(did.into()) {
return;
}

Expand Down Expand Up @@ -470,7 +470,7 @@ fn build_module(
items.push(clean::Item {
name: None,
attrs: box clean::Attributes::default(),
def_id: cx.next_def_id(did.krate),
def_id: FakeDefId::new_fake(did.krate),
visibility: clean::Public,
kind: box clean::ImportItem(clean::Import::new_simple(
item.ident.name,
Expand Down
27 changes: 18 additions & 9 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ impl Clean<Generics> for hir::Generics<'_> {
match param.kind {
GenericParamDefKind::Lifetime => unreachable!(),
GenericParamDefKind::Type { did, ref bounds, .. } => {
cx.impl_trait_bounds.insert(did.into(), bounds.clone());
cx.impl_trait_bounds
.insert(FakeDefId::new_real(did).into(), bounds.clone());
}
GenericParamDefKind::Const { .. } => unreachable!(),
}
Expand Down Expand Up @@ -614,7 +615,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
.collect::<Vec<GenericParamDef>>();

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

let where_predicates = preds
.predicates
Expand Down Expand Up @@ -663,10 +664,11 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
if let Some(((_, trait_did, name), rhs)) =
proj.as_ref().and_then(|(lhs, rhs)| Some((lhs.projection()?, rhs)))
{
impl_trait_proj
.entry(param_idx)
.or_default()
.push((trait_did, name, rhs));
impl_trait_proj.entry(param_idx).or_default().push((
trait_did.into(),
name,
rhs,
));
}

return None;
Expand All @@ -685,7 +687,13 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
if let Some(proj) = impl_trait_proj.remove(&idx) {
for (trait_did, name, rhs) in proj {
let rhs = rhs.clean(cx);
simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs);
simplify::merge_bounds(
cx,
&mut bounds,
trait_did.expect_real(),
name,
&rhs,
);
}
}
} else {
Expand Down Expand Up @@ -1175,7 +1183,8 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
if let Some(new_ty) = cx.ty_substs.get(&did).cloned() {
return new_ty;
}
if let Some(bounds) = cx.impl_trait_bounds.remove(&did.into()) {
if let Some(bounds) = cx.impl_trait_bounds.remove(&FakeDefId::new_real(did).into())
{
return ImplTrait(bounds);
}
}
Expand Down Expand Up @@ -2006,7 +2015,7 @@ fn clean_extern_crate(
vec![Item {
name: Some(name),
attrs: box attrs.clean(cx),
def_id: crate_def_id,
def_id: crate_def_id.into(),
visibility: krate.vis.clean(cx),
kind: box ExternCrateItem { src: orig_name },
cfg: attrs.cfg(cx.sess().diagnostic()),
Expand Down
Loading

0 comments on commit ae8b84b

Please sign in to comment.