Skip to content

Commit 6fb7924

Browse files
authored
Rollup merge of #80744 - camelid:next_def_id-docs, r=jyn514
rustdoc: Turn `next_def_id` comments into docs Split out from #80740. r? ``@jyn514``
2 parents 94a27f2 + 7428e2d commit 6fb7924

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/librustdoc/clean/types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ impl Item {
291291
}
292292
}
293293

294-
/// See comments on next_def_id
294+
/// See the documentation for [`next_def_id()`].
295+
///
296+
/// [`next_def_id()`]: DocContext::next_def_id()
295297
crate fn is_fake(&self) -> bool {
296298
MAX_DEF_ID.with(|m| {
297299
m.borrow().get(&self.def_id.krate).map(|id| self.def_id >= *id).unwrap_or(false)

src/librustdoc/core.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,20 @@ impl<'tcx> DocContext<'tcx> {
120120
r
121121
}
122122

123-
// This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly
124-
// refactoring either librustdoc or librustc_middle. In particular, allowing new DefIds to be
125-
// registered after the AST is constructed would require storing the defid mapping in a
126-
// RefCell, decreasing the performance for normal compilation for very little gain.
127-
//
128-
// Instead, we construct 'fake' def ids, which start immediately after the last DefId.
129-
// In the Debug impl for clean::Item, we explicitly check for fake
130-
// def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds
123+
/// Create a new "fake" [`DefId`].
124+
///
125+
/// This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly
126+
/// refactoring either rustdoc or [`rustc_middle`]. In particular, allowing new [`DefId`]s
127+
/// to be registered after the AST is constructed would require storing the [`DefId`] mapping
128+
/// in a [`RefCell`], decreasing the performance for normal compilation for very little gain.
129+
///
130+
/// Instead, we construct "fake" [`DefId`]s, which start immediately after the last `DefId`.
131+
/// In the [`Debug`] impl for [`clean::Item`], we explicitly check for fake `DefId`s,
132+
/// as we'll end up with a panic if we use the `DefId` `Debug` impl for fake `DefId`s.
133+
///
134+
/// [`RefCell`]: std::cell::RefCell
135+
/// [`Debug`]: std::fmt::Debug
136+
/// [`clean::Item`]: crate::clean::types::Item
131137
crate fn next_def_id(&self, crate_num: CrateNum) -> DefId {
132138
let start_def_id = {
133139
let num_def_ids = if crate_num == LOCAL_CRATE {

0 commit comments

Comments
 (0)