Skip to content

Commit

Permalink
Rollup merge of #96118 - GuillaumeGomez:cleanup-def-id-item-id, r=not…
Browse files Browse the repository at this point in the history
…riddle

rustdoc: Rename `def_id` into `item_id` when the type is `ItemId` for readability

As `@notriddle` mentioned in #96091, the field name is inaccurate. This PR fixes it by renaming it accordingly to its real type.

r? `@notriddle`
  • Loading branch information
Dylan-DPC authored Apr 16, 2022
2 parents 5d98ce6 + b1e6211 commit 10e0db5
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
unsafety: hir::Unsafety::Normal,
generics: new_generics,
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 @@ -105,7 +105,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
unsafety: hir::Unsafety::Normal,
generics: clean_ty_generics(
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ fn build_module(
items.push(clean::Item {
name: None,
attrs: box clean::Attributes::default(),
def_id: ItemId::Primitive(prim_ty, did.krate),
item_id: ItemId::Primitive(prim_ty, did.krate),
visibility: clean::Public,
kind: box clean::ImportItem(clean::Import::new_simple(
item.ident.name,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ fn clean_extern_crate(
vec![Item {
name: Some(name),
attrs: box attrs.clean(cx),
def_id: crate_def_id.into(),
item_id: crate_def_id.into(),
visibility: ty_vis.clean(cx),
kind: box ExternCrateItem { src: orig_name },
cfg: attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
Expand Down
30 changes: 15 additions & 15 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ crate struct Item {
/// Information about this item that is specific to what kind of item it is.
/// E.g., struct vs enum vs function.
crate kind: Box<ItemKind>,
crate def_id: ItemId,
crate item_id: ItemId,

crate cfg: Option<Arc<Cfg>>,
}
Expand All @@ -380,7 +380,7 @@ impl fmt::Debug for Item {
let mut fmt = f.debug_struct("Item");
fmt.field("name", &self.name)
.field("visibility", &self.visibility)
.field("def_id", &self.def_id);
.field("item_id", &self.item_id);
// allow printing the full item if someone really wants to
if alternate {
fmt.field("attrs", &self.attrs).field("kind", &self.kind).field("cfg", &self.cfg);
Expand Down Expand Up @@ -408,19 +408,19 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {

impl Item {
crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
self.def_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
}

crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
self.def_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
self.item_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
}

crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {
self.def_id.as_def_id().and_then(|did| tcx.lookup_deprecation(did))
self.item_id.as_def_id().and_then(|did| tcx.lookup_deprecation(did))
}

crate fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
self.def_id.as_def_id().map(|did| tcx.get_attrs(did).inner_docs()).unwrap_or(false)
self.item_id.as_def_id().map(|did| tcx.get_attrs(did).inner_docs()).unwrap_or(false)
}

crate fn span(&self, tcx: TyCtxt<'_>) -> Span {
Expand All @@ -432,14 +432,14 @@ impl Item {
ItemKind::ModuleItem(Module { span, .. }) => *span,
ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => Span::dummy(),
ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => {
if let ItemId::Blanket { impl_id, .. } = self.def_id {
if let ItemId::Blanket { impl_id, .. } = self.item_id {
rustc_span(impl_id, tcx)
} else {
panic!("blanket impl item has non-blanket ID")
}
}
_ => {
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
self.item_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
}
}
}
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Item {
cx.tcx.visibility(def_id).clean(cx)
};

Item { def_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
Item { item_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
}

/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
Expand All @@ -517,7 +517,7 @@ impl Item {

cx.cache()
.intra_doc_links
.get(&self.def_id)
.get(&self.item_id)
.map_or(&[][..], |v| v.as_slice())
.iter()
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
Expand Down Expand Up @@ -547,7 +547,7 @@ impl Item {
crate fn link_names(&self, cache: &Cache) -> Vec<RenderedLink> {
cache
.intra_doc_links
.get(&self.def_id)
.get(&self.item_id)
.map_or(&[][..], |v| v.as_slice())
.iter()
.map(|ItemLink { link: s, link_text, .. }| RenderedLink {
Expand All @@ -559,7 +559,7 @@ impl Item {
}

crate fn is_crate(&self) -> bool {
self.is_mod() && self.def_id.as_def_id().map_or(false, |did| did.index == CRATE_DEF_INDEX)
self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.index == CRATE_DEF_INDEX)
}
crate fn is_mod(&self) -> bool {
self.type_() == ItemType::Module
Expand Down Expand Up @@ -695,7 +695,7 @@ impl Item {
}
let header = match *self.kind {
ItemKind::ForeignFunctionItem(_) => {
let abi = tcx.fn_sig(self.def_id.as_def_id().unwrap()).abi();
let abi = tcx.fn_sig(self.item_id.as_def_id().unwrap()).abi();
hir::FnHeader {
unsafety: if abi == Abi::RustIntrinsic {
intrinsic_operation_unsafety(self.name.unwrap())
Expand All @@ -708,11 +708,11 @@ impl Item {
}
}
ItemKind::FunctionItem(_) | ItemKind::MethodItem(_, _) => {
let def_id = self.def_id.as_def_id().unwrap();
let def_id = self.item_id.as_def_id().unwrap();
build_fn_header(def_id, tcx, tcx.asyncness(def_id))
}
ItemKind::TyMethodItem(_) => {
build_fn_header(self.def_id.as_def_id().unwrap(), tcx, hir::IsAsync::NotAsync)
build_fn_header(self.item_id.as_def_id().unwrap(), tcx, hir::IsAsync::NotAsync)
}
_ => return None,
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
// `#[doc(masked)]` to the injected `extern crate` because it's unstable.
if it.is_extern_crate()
&& (it.attrs.has_doc_flag(sym::masked)
|| cx.tcx.is_compiler_builtins(it.def_id.krate()))
|| cx.tcx.is_compiler_builtins(it.item_id.krate()))
{
cx.cache.masked_crates.insert(it.def_id.krate());
cx.cache.masked_crates.insert(it.item_id.krate());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ impl<'tcx> DocContext<'tcx> {

/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
/// (This avoids a slice-index-out-of-bounds panic.)
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: ItemId) -> Option<HirId> {
match def_id {
crate fn as_local_hir_id(tcx: TyCtxt<'_>, item_id: ItemId) -> Option<HirId> {
match item_id {
ItemId::DefId(real_id) => {
real_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
}
Expand Down Expand Up @@ -390,7 +390,7 @@ crate fn run_global_ctxt(
);
tcx.struct_lint_node(
crate::lint::MISSING_CRATE_LEVEL_DOCS,
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
|lint| {
let mut diag =
lint.build("no documentation found for this crate's top-level module");
Expand Down
20 changes: 10 additions & 10 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ impl Cache {

impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
if item.def_id.is_local() {
debug!("folding {} \"{:?}\", id {:?}", item.type_(), item.name, item.def_id);
if item.item_id.is_local() {
debug!("folding {} \"{:?}\", id {:?}", item.type_(), item.name, item.item_id);
}

// If this is a stripped module,
Expand All @@ -202,7 +202,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// If the impl is from a masked crate or references something from a
// masked crate then remove it completely.
if let clean::ImplItem(ref i) = *item.kind {
if self.cache.masked_crates.contains(&item.def_id.krate())
if self.cache.masked_crates.contains(&item.item_id.krate())
|| i.trait_
.as_ref()
.map_or(false, |t| self.cache.masked_crates.contains(&t.def_id().krate))
Expand All @@ -217,7 +217,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Propagate a trait method's documentation to all implementors of the
// trait.
if let clean::TraitItem(ref t) = *item.kind {
self.cache.traits.entry(item.def_id.expect_def_id()).or_insert_with(|| {
self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| {
clean::TraitWithExtraInfo {
trait_: t.clone(),
is_notable: item.attrs.has_doc_flag(sym::notable_trait),
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// A crate has a module at its root, containing all items,
// which should not be indexed. The crate-item itself is
// inserted later on when serializing the search-index.
if item.def_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) {
if item.item_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) {
let desc = item.doc_value().map_or_else(String::new, |x| {
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
});
Expand Down Expand Up @@ -351,11 +351,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// `public_items` map, so we can skip inserting into the
// paths map if there was already an entry present and we're
// not a public item.
if !self.cache.paths.contains_key(&item.def_id.expect_def_id())
|| self.cache.access_levels.is_public(item.def_id.expect_def_id())
if !self.cache.paths.contains_key(&item.item_id.expect_def_id())
|| self.cache.access_levels.is_public(item.item_id.expect_def_id())
{
self.cache.paths.insert(
item.def_id.expect_def_id(),
item.item_id.expect_def_id(),
(self.cache.stack.clone(), item.type_()),
);
}
Expand All @@ -364,7 +364,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
clean::PrimitiveItem(..) => {
self.cache
.paths
.insert(item.def_id.expect_def_id(), (self.cache.stack.clone(), item.type_()));
.insert(item.item_id.expect_def_id(), (self.cache.stack.clone(), item.type_()));
}

clean::ExternCrateItem { .. }
Expand Down Expand Up @@ -396,7 +396,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
| clean::StructItem(..)
| clean::UnionItem(..)
| clean::VariantItem(..) => {
self.cache.parent_stack.push(item.def_id.expect_def_id());
self.cache.parent_stack.push(item.item_id.expect_def_id());
self.cache.parent_is_trait_impl = false;
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl<'tcx> Context<'tcx> {
&self.shared.style_files,
)
} else {
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.def_id.expect_def_id()) {
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id()) {
if self.current.len() + 1 != names.len()
|| self.current.iter().zip(names.iter()).any(|(a, b)| a != b)
{
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ fn assoc_const(
w,
"{extra}{vis}const <a{href} class=\"constant\">{name}</a>: {ty}",
extra = extra,
vis = it.visibility.print_with_space(it.def_id, cx),
vis = it.visibility.print_with_space(it.item_id, cx),
href = assoc_href_attr(it, link, cx),
name = it.name.as_ref().unwrap(),
ty = ty.print(cx),
Expand Down Expand Up @@ -884,7 +884,7 @@ fn assoc_method(
) {
let header = meth.fn_header(cx.tcx()).expect("Trying to get header from a non-function item");
let name = meth.name.as_ref().unwrap();
let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
let vis = meth.visibility.print_with_space(meth.item_id, cx).to_string();
// FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
// this condition.
let constness = match render_mode {
Expand Down Expand Up @@ -2060,7 +2060,7 @@ fn small_url_encode(s: String) -> String {
}

fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
let did = it.def_id.expect_def_id();
let did = it.item_id.expect_def_id();
let cache = cx.cache();

if let Some(v) = cache.impls.get(&did) {
Expand Down Expand Up @@ -2412,7 +2412,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
);

let cache = cx.cache();
if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) {
if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
let mut res = implementors
.iter()
.filter(|i| {
Expand Down Expand Up @@ -2761,7 +2761,7 @@ const NUM_VISIBLE_LINES: usize = 10;
/// Generates the HTML for example call locations generated via the --scrape-examples flag.
fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
let tcx = cx.tcx();
let def_id = item.def_id.expect_def_id();
let def_id = item.item_id.expect_def_id();
let key = tcx.def_path_hash(def_id);
let Some(call_locations) = cx.shared.call_locations.get(&key) else { return };

Expand Down
Loading

0 comments on commit 10e0db5

Please sign in to comment.