Skip to content

Commit 10e0db5

Browse files
authored
Rollup merge of rust-lang#96118 - GuillaumeGomez:cleanup-def-id-item-id, r=notriddle
rustdoc: Rename `def_id` into `item_id` when the type is `ItemId` for readability As `@notriddle` mentioned in rust-lang#96091, the field name is inaccurate. This PR fixes it by renaming it accordingly to its real type. r? `@notriddle`
2 parents 5d98ce6 + b1e6211 commit 10e0db5

23 files changed

+121
-120
lines changed

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
116116
name: None,
117117
attrs: Default::default(),
118118
visibility: Inherited,
119-
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
119+
item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
120120
kind: box ImplItem(Impl {
121121
unsafety: hir::Unsafety::Normal,
122122
generics: new_generics,

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
105105
name: None,
106106
attrs: Default::default(),
107107
visibility: Inherited,
108-
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
108+
item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
109109
kind: box ImplItem(Impl {
110110
unsafety: hir::Unsafety::Normal,
111111
generics: clean_ty_generics(

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ fn build_module(
534534
items.push(clean::Item {
535535
name: None,
536536
attrs: box clean::Attributes::default(),
537-
def_id: ItemId::Primitive(prim_ty, did.krate),
537+
item_id: ItemId::Primitive(prim_ty, did.krate),
538538
visibility: clean::Public,
539539
kind: box clean::ImportItem(clean::Import::new_simple(
540540
item.ident.name,

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ fn clean_extern_crate(
20092009
vec![Item {
20102010
name: Some(name),
20112011
attrs: box attrs.clean(cx),
2012-
def_id: crate_def_id.into(),
2012+
item_id: crate_def_id.into(),
20132013
visibility: ty_vis.clean(cx),
20142014
kind: box ExternCrateItem { src: orig_name },
20152015
cfg: attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),

src/librustdoc/clean/types.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ crate struct Item {
366366
/// Information about this item that is specific to what kind of item it is.
367367
/// E.g., struct vs enum vs function.
368368
crate kind: Box<ItemKind>,
369-
crate def_id: ItemId,
369+
crate item_id: ItemId,
370370

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

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

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

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

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

426426
crate fn span(&self, tcx: TyCtxt<'_>) -> Span {
@@ -432,14 +432,14 @@ impl Item {
432432
ItemKind::ModuleItem(Module { span, .. }) => *span,
433433
ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => Span::dummy(),
434434
ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => {
435-
if let ItemId::Blanket { impl_id, .. } = self.def_id {
435+
if let ItemId::Blanket { impl_id, .. } = self.item_id {
436436
rustc_span(impl_id, tcx)
437437
} else {
438438
panic!("blanket impl item has non-blanket ID")
439439
}
440440
}
441441
_ => {
442-
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
442+
self.item_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
443443
}
444444
}
445445
}
@@ -503,7 +503,7 @@ impl Item {
503503
cx.tcx.visibility(def_id).clean(cx)
504504
};
505505

506-
Item { def_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
506+
Item { item_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg }
507507
}
508508

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

518518
cx.cache()
519519
.intra_doc_links
520-
.get(&self.def_id)
520+
.get(&self.item_id)
521521
.map_or(&[][..], |v| v.as_slice())
522522
.iter()
523523
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
@@ -547,7 +547,7 @@ impl Item {
547547
crate fn link_names(&self, cache: &Cache) -> Vec<RenderedLink> {
548548
cache
549549
.intra_doc_links
550-
.get(&self.def_id)
550+
.get(&self.item_id)
551551
.map_or(&[][..], |v| v.as_slice())
552552
.iter()
553553
.map(|ItemLink { link: s, link_text, .. }| RenderedLink {
@@ -559,7 +559,7 @@ impl Item {
559559
}
560560

561561
crate fn is_crate(&self) -> bool {
562-
self.is_mod() && self.def_id.as_def_id().map_or(false, |did| did.index == CRATE_DEF_INDEX)
562+
self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.index == CRATE_DEF_INDEX)
563563
}
564564
crate fn is_mod(&self) -> bool {
565565
self.type_() == ItemType::Module
@@ -695,7 +695,7 @@ impl Item {
695695
}
696696
let header = match *self.kind {
697697
ItemKind::ForeignFunctionItem(_) => {
698-
let abi = tcx.fn_sig(self.def_id.as_def_id().unwrap()).abi();
698+
let abi = tcx.fn_sig(self.item_id.as_def_id().unwrap()).abi();
699699
hir::FnHeader {
700700
unsafety: if abi == Abi::RustIntrinsic {
701701
intrinsic_operation_unsafety(self.name.unwrap())
@@ -708,11 +708,11 @@ impl Item {
708708
}
709709
}
710710
ItemKind::FunctionItem(_) | ItemKind::MethodItem(_, _) => {
711-
let def_id = self.def_id.as_def_id().unwrap();
711+
let def_id = self.item_id.as_def_id().unwrap();
712712
build_fn_header(def_id, tcx, tcx.asyncness(def_id))
713713
}
714714
ItemKind::TyMethodItem(_) => {
715-
build_fn_header(self.def_id.as_def_id().unwrap(), tcx, hir::IsAsync::NotAsync)
715+
build_fn_header(self.item_id.as_def_id().unwrap(), tcx, hir::IsAsync::NotAsync)
716716
}
717717
_ => return None,
718718
};

src/librustdoc/clean/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
4444
// `#[doc(masked)]` to the injected `extern crate` because it's unstable.
4545
if it.is_extern_crate()
4646
&& (it.attrs.has_doc_flag(sym::masked)
47-
|| cx.tcx.is_compiler_builtins(it.def_id.krate()))
47+
|| cx.tcx.is_compiler_builtins(it.item_id.krate()))
4848
{
49-
cx.cache.masked_crates.insert(it.def_id.krate());
49+
cx.cache.masked_crates.insert(it.item_id.krate());
5050
}
5151
}
5252
}

src/librustdoc/core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ impl<'tcx> DocContext<'tcx> {
113113

114114
/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
115115
/// (This avoids a slice-index-out-of-bounds panic.)
116-
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: ItemId) -> Option<HirId> {
117-
match def_id {
116+
crate fn as_local_hir_id(tcx: TyCtxt<'_>, item_id: ItemId) -> Option<HirId> {
117+
match item_id {
118118
ItemId::DefId(real_id) => {
119119
real_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
120120
}
@@ -390,7 +390,7 @@ crate fn run_global_ctxt(
390390
);
391391
tcx.struct_lint_node(
392392
crate::lint::MISSING_CRATE_LEVEL_DOCS,
393-
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
393+
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
394394
|lint| {
395395
let mut diag =
396396
lint.build("no documentation found for this crate's top-level module");

src/librustdoc/formats/cache.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ impl Cache {
186186

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

193193
// If this is a stripped module,
@@ -202,7 +202,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
202202
// If the impl is from a masked crate or references something from a
203203
// masked crate then remove it completely.
204204
if let clean::ImplItem(ref i) = *item.kind {
205-
if self.cache.masked_crates.contains(&item.def_id.krate())
205+
if self.cache.masked_crates.contains(&item.item_id.krate())
206206
|| i.trait_
207207
.as_ref()
208208
.map_or(false, |t| self.cache.masked_crates.contains(&t.def_id().krate))
@@ -217,7 +217,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
217217
// Propagate a trait method's documentation to all implementors of the
218218
// trait.
219219
if let clean::TraitItem(ref t) = *item.kind {
220-
self.cache.traits.entry(item.def_id.expect_def_id()).or_insert_with(|| {
220+
self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| {
221221
clean::TraitWithExtraInfo {
222222
trait_: t.clone(),
223223
is_notable: item.attrs.has_doc_flag(sym::notable_trait),
@@ -293,7 +293,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
293293
// A crate has a module at its root, containing all items,
294294
// which should not be indexed. The crate-item itself is
295295
// inserted later on when serializing the search-index.
296-
if item.def_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) {
296+
if item.item_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) {
297297
let desc = item.doc_value().map_or_else(String::new, |x| {
298298
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
299299
});
@@ -351,11 +351,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
351351
// `public_items` map, so we can skip inserting into the
352352
// paths map if there was already an entry present and we're
353353
// not a public item.
354-
if !self.cache.paths.contains_key(&item.def_id.expect_def_id())
355-
|| self.cache.access_levels.is_public(item.def_id.expect_def_id())
354+
if !self.cache.paths.contains_key(&item.item_id.expect_def_id())
355+
|| self.cache.access_levels.is_public(item.item_id.expect_def_id())
356356
{
357357
self.cache.paths.insert(
358-
item.def_id.expect_def_id(),
358+
item.item_id.expect_def_id(),
359359
(self.cache.stack.clone(), item.type_()),
360360
);
361361
}
@@ -364,7 +364,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
364364
clean::PrimitiveItem(..) => {
365365
self.cache
366366
.paths
367-
.insert(item.def_id.expect_def_id(), (self.cache.stack.clone(), item.type_()));
367+
.insert(item.item_id.expect_def_id(), (self.cache.stack.clone(), item.type_()));
368368
}
369369

370370
clean::ExternCrateItem { .. }
@@ -396,7 +396,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
396396
| clean::StructItem(..)
397397
| clean::UnionItem(..)
398398
| clean::VariantItem(..) => {
399-
self.cache.parent_stack.push(item.def_id.expect_def_id());
399+
self.cache.parent_stack.push(item.item_id.expect_def_id());
400400
self.cache.parent_is_trait_impl = false;
401401
true
402402
}

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'tcx> Context<'tcx> {
222222
&self.shared.style_files,
223223
)
224224
} else {
225-
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.def_id.expect_def_id()) {
225+
if let Some(&(ref names, ty)) = self.cache().paths.get(&it.item_id.expect_def_id()) {
226226
if self.current.len() + 1 != names.len()
227227
|| self.current.iter().zip(names.iter()).any(|(a, b)| a != b)
228228
{

src/librustdoc/html/render/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ fn assoc_const(
830830
w,
831831
"{extra}{vis}const <a{href} class=\"constant\">{name}</a>: {ty}",
832832
extra = extra,
833-
vis = it.visibility.print_with_space(it.def_id, cx),
833+
vis = it.visibility.print_with_space(it.item_id, cx),
834834
href = assoc_href_attr(it, link, cx),
835835
name = it.name.as_ref().unwrap(),
836836
ty = ty.print(cx),
@@ -884,7 +884,7 @@ fn assoc_method(
884884
) {
885885
let header = meth.fn_header(cx.tcx()).expect("Trying to get header from a non-function item");
886886
let name = meth.name.as_ref().unwrap();
887-
let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
887+
let vis = meth.visibility.print_with_space(meth.item_id, cx).to_string();
888888
// FIXME: Once https://github.com./rust-lang/rust/issues/67792 is implemented, we can remove
889889
// this condition.
890890
let constness = match render_mode {
@@ -2060,7 +2060,7 @@ fn small_url_encode(s: String) -> String {
20602060
}
20612061

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

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

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

0 commit comments

Comments
 (0)