Skip to content

Commit

Permalink
rustdoc: Add PrimitiveType to ItemId::Primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Stupremee committed Jul 5, 2021
1 parent 4b1027a commit 21424d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,11 @@ fn build_module(
}
if let Res::PrimTy(p) = item.res {
// Primitive types can't be inlined so generate an import instead.
let prim_ty = clean::PrimitiveType::from(p);
items.push(clean::Item {
name: None,
attrs: box clean::Attributes::default(),
def_id: ItemId::Primitive(did.krate),
def_id: ItemId::Primitive(prim_ty, did.krate),
visibility: clean::Public,
kind: box clean::ImportItem(clean::Import::new_simple(
item.ident.name,
Expand All @@ -495,7 +496,7 @@ fn build_module(
global: false,
res: item.res,
segments: vec![clean::PathSegment {
name: clean::PrimitiveType::from(p).as_sym(),
name: prim_ty.as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Vec::new(),
bindings: Vec::new(),
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use self::Type::*;

crate type ItemIdSet = FxHashSet<ItemId>;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
crate enum ItemId {
/// A "normal" item that uses a [`DefId`] for identification.
DefId(DefId),
Expand All @@ -59,7 +59,7 @@ crate enum ItemId {
/// Identifier that is used for blanket implementations.
Blanket { trait_: DefId, for_: DefId },
/// Identifier for primitive types.
Primitive(CrateNum),
Primitive(PrimitiveType, CrateNum),
}

impl ItemId {
Expand All @@ -69,7 +69,7 @@ impl ItemId {
ItemId::Auto { for_: id, .. }
| ItemId::Blanket { for_: id, .. }
| ItemId::DefId(id) => id.is_local(),
ItemId::Primitive(krate) => krate == LOCAL_CRATE,
ItemId::Primitive(_, krate) => krate == LOCAL_CRATE,
}
}

Expand All @@ -94,7 +94,7 @@ impl ItemId {
ItemId::Auto { for_: id, .. }
| ItemId::Blanket { for_: id, .. }
| ItemId::DefId(id) => id.krate,
ItemId::Primitive(krate) => krate,
ItemId::Primitive(_, krate) => krate,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ crate struct Cache {
/// All intra-doc links resolved so far.
///
/// Links are indexed by the DefId of the item they document.
crate intra_doc_links: BTreeMap<ItemId, Vec<clean::ItemLink>>,
crate intra_doc_links: FxHashMap<ItemId, Vec<clean::ItemLink>>,
}

/// This struct is used to wrap the `cache` and `tcx` in order to run `DocFolder`.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ crate fn from_item_id(did: ItemId) -> Id {
ItemId::Auto { for_, trait_ } => {
Id(format!("a:{}-{}", DisplayDefId(trait_), DisplayDefId(for_)))
}
ItemId::Primitive(krate) => Id(format!("p:{}", krate.as_u32())),
ItemId::Primitive(ty, krate) => Id(format!("p:{}:{}", krate.as_u32(), ty.as_sym())),
}
}

Expand Down

0 comments on commit 21424d2

Please sign in to comment.