Skip to content

Commit e80c9ac

Browse files
committed
rustdoc: use LocalDefId for inline stmt
It's never a cross-crate DefId, so save space by not storing it.
1 parent 878f49f commit e80c9ac

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/librustdoc/clean/inline.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55

66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir::def::{DefKind, Res};
8-
use rustc_hir::def_id::{DefId, DefIdSet, LocalModDefId};
8+
use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModDefId};
99
use rustc_hir::Mutability;
1010
use rustc_metadata::creader::{CStore, LoadedMacro};
1111
use rustc_middle::ty::fast_reject::SimplifiedType;
@@ -43,7 +43,7 @@ pub(crate) fn try_inline(
4343
cx: &mut DocContext<'_>,
4444
res: Res,
4545
name: Symbol,
46-
attrs: Option<(&[ast::Attribute], Option<DefId>)>,
46+
attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
4747
visited: &mut DefIdSet,
4848
) -> Option<Vec<clean::Item>> {
4949
let did = res.opt_def_id()?;
@@ -157,7 +157,7 @@ pub(crate) fn try_inline(
157157
kind,
158158
did,
159159
name,
160-
import_def_id.and_then(|def_id| def_id.as_local()),
160+
import_def_id,
161161
None,
162162
);
163163
// The visibility needs to reflect the one from the reexport and not from the "source" DefId.
@@ -198,7 +198,7 @@ pub(crate) fn try_inline_glob(
198198
visited,
199199
inlined_names,
200200
Some(&reexports),
201-
Some((attrs, Some(import.owner_id.def_id.to_def_id()))),
201+
Some((attrs, Some(import.owner_id.def_id))),
202202
);
203203
items.retain(|item| {
204204
if let Some(name) = item.name {
@@ -372,7 +372,7 @@ fn build_type_alias(
372372
pub(crate) fn build_impls(
373373
cx: &mut DocContext<'_>,
374374
did: DefId,
375-
attrs: Option<(&[ast::Attribute], Option<DefId>)>,
375+
attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
376376
ret: &mut Vec<clean::Item>,
377377
) {
378378
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_inherent_impls");
@@ -405,7 +405,7 @@ pub(crate) fn build_impls(
405405
pub(crate) fn merge_attrs(
406406
cx: &mut DocContext<'_>,
407407
old_attrs: &[ast::Attribute],
408-
new_attrs: Option<(&[ast::Attribute], Option<DefId>)>,
408+
new_attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
409409
) -> (clean::Attributes, Option<Arc<clean::cfg::Cfg>>) {
410410
// NOTE: If we have additional attributes (from a re-export),
411411
// always insert them first. This ensure that re-export
@@ -416,7 +416,7 @@ pub(crate) fn merge_attrs(
416416
both.extend_from_slice(old_attrs);
417417
(
418418
if let Some(item_id) = item_id {
419-
Attributes::from_ast_with_additional(old_attrs, (inner, item_id))
419+
Attributes::from_ast_with_additional(old_attrs, (inner, item_id.to_def_id()))
420420
} else {
421421
Attributes::from_ast(&both)
422422
},
@@ -431,7 +431,7 @@ pub(crate) fn merge_attrs(
431431
pub(crate) fn build_impl(
432432
cx: &mut DocContext<'_>,
433433
did: DefId,
434-
attrs: Option<(&[ast::Attribute], Option<DefId>)>,
434+
attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
435435
ret: &mut Vec<clean::Item>,
436436
) {
437437
if !cx.inlined.insert(did.into()) {
@@ -641,7 +641,7 @@ fn build_module_items(
641641
visited: &mut DefIdSet,
642642
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
643643
allowed_def_ids: Option<&DefIdSet>,
644-
attrs: Option<(&[ast::Attribute], Option<DefId>)>,
644+
attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
645645
) -> Vec<clean::Item> {
646646
let mut items = Vec::new();
647647

@@ -745,15 +745,15 @@ fn build_macro(
745745
cx: &mut DocContext<'_>,
746746
def_id: DefId,
747747
name: Symbol,
748-
import_def_id: Option<DefId>,
748+
import_def_id: Option<LocalDefId>,
749749
macro_kind: MacroKind,
750750
is_doc_hidden: bool,
751751
) -> clean::ItemKind {
752752
match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.tcx) {
753753
LoadedMacro::MacroDef(item_def, _) => match macro_kind {
754754
MacroKind::Bang => {
755755
if let ast::ItemKind::MacroDef(ref def) = item_def.kind {
756-
let vis = cx.tcx.visibility(import_def_id.unwrap_or(def_id));
756+
let vis = cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id));
757757
clean::MacroItem(clean::Macro {
758758
source: utils::display_macro_source(
759759
cx,

src/librustdoc/clean/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn generate_item_with_correct_attrs(
204204

205205
let name = renamed.or(Some(name));
206206
let mut item = Item::from_def_id_and_attrs_and_parts(def_id, name, kind, Box::new(attrs), cfg);
207-
item.inline_stmt_id = import_id.map(|local| local.to_def_id());
207+
item.inline_stmt_id = import_id;
208208
item
209209
}
210210

@@ -2927,7 +2927,7 @@ fn clean_extern_crate<'tcx>(
29272927
})
29282928
&& !cx.output_format.is_json();
29292929

2930-
let krate_owner_def_id = krate.owner_id.to_def_id();
2930+
let krate_owner_def_id = krate.owner_id.def_id;
29312931
if please_inline {
29322932
if let Some(items) = inline::try_inline(
29332933
cx,
@@ -2941,7 +2941,7 @@ fn clean_extern_crate<'tcx>(
29412941
}
29422942

29432943
vec![Item::from_def_id_and_parts(
2944-
krate_owner_def_id,
2944+
krate_owner_def_id.to_def_id(),
29452945
Some(name),
29462946
ExternCrateItem { src: orig_name },
29472947
cx,
@@ -2988,7 +2988,7 @@ fn clean_use_statement_inner<'tcx>(
29882988
let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline);
29892989
let pub_underscore = visibility.is_public() && name == kw::Underscore;
29902990
let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id);
2991-
let import_def_id = import.owner_id.def_id.to_def_id();
2991+
let import_def_id = import.owner_id.def_id;
29922992

29932993
// The parent of the module in which this import resides. This
29942994
// is the same as `current_mod` if that's already the top
@@ -3071,7 +3071,7 @@ fn clean_use_statement_inner<'tcx>(
30713071
)
30723072
{
30733073
items.push(Item::from_def_id_and_parts(
3074-
import_def_id,
3074+
import_def_id.to_def_id(),
30753075
None,
30763076
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
30773077
cx,
@@ -3081,7 +3081,7 @@ fn clean_use_statement_inner<'tcx>(
30813081
Import::new_simple(name, resolve_use_source(cx, path), true)
30823082
};
30833083

3084-
vec![Item::from_def_id_and_parts(import_def_id, None, ImportItem(inner), cx)]
3084+
vec![Item::from_def_id_and_parts(import_def_id.to_def_id(), None, ImportItem(inner), cx)]
30853085
}
30863086

30873087
fn clean_maybe_renamed_foreign_item<'tcx>(

src/librustdoc/clean/types.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ pub(crate) struct Item {
325325
/// E.g., struct vs enum vs function.
326326
pub(crate) kind: Box<ItemKind>,
327327
pub(crate) item_id: ItemId,
328-
/// This is the `DefId` of the `use` statement if the item was inlined.
329-
pub(crate) inline_stmt_id: Option<DefId>,
328+
/// This is the `LocalDefId` of the `use` statement if the item was inlined.
329+
/// The crate metadata doesn't hold this information, so the `use` statement
330+
/// always belongs to the current crate.
331+
pub(crate) inline_stmt_id: Option<LocalDefId>,
330332
pub(crate) cfg: Option<Arc<Cfg>>,
331333
}
332334

@@ -702,7 +704,7 @@ impl Item {
702704
_ => {}
703705
}
704706
let def_id = match self.inline_stmt_id {
705-
Some(inlined) => inlined,
707+
Some(inlined) => inlined.to_def_id(),
706708
None => def_id,
707709
};
708710
Some(tcx.visibility(def_id))

0 commit comments

Comments
 (0)