Skip to content

Commit 19876d1

Browse files
Simplify code and improve code comments
1 parent 24e40f0 commit 19876d1

3 files changed

Lines changed: 25 additions & 36 deletions

File tree

src/librustdoc/clean/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,10 +2777,10 @@ fn clean_maybe_renamed_item<'tcx>(
27772777
// before.
27782778
match item.kind {
27792779
ItemKind::Impl(ref impl_) => {
2780-
// `renamed` is passed down to `clean_impl` because we use it as a marker to
2781-
// indicate that this is an inlined impl and that we should generate an impl
2782-
// placeholder and not a "real" impl item.
2783-
return clean_impl(impl_, item.owner_id.def_id, cx, renamed);
2780+
// If `renamed` is `Some()` for an `impl`, it means it's been inlined because we use
2781+
// it as a marker to indicate that this is an inlined impl and that we should
2782+
// generate an impl placeholder and not a "real" impl item.
2783+
return clean_impl(impl_, item.owner_id.def_id, cx, renamed.is_some());
27842784
}
27852785
ItemKind::Use(path, kind) => {
27862786
return clean_use_statement(
@@ -2914,16 +2914,16 @@ fn clean_impl<'tcx>(
29142914
impl_: &hir::Impl<'tcx>,
29152915
def_id: LocalDefId,
29162916
cx: &mut DocContext<'tcx>,
2917-
// If `renamed` is some, then `impl_` is an inlined impl and it will be handled later on in the
2918-
// code. In here, we will generate a placeholder for it in order to be able to compute its
2917+
// If true, this is an inlined impl and it will be handled later on in the code.
2918+
// In here, we will generate a placeholder for it in order to be able to compute its
29192919
// `doc_cfg` info.
2920-
renamed: Option<Symbol>,
2920+
is_inlined: bool,
29212921
) -> Vec<Item> {
29222922
let tcx = cx.tcx;
29232923
let mut ret = Vec::new();
29242924
let trait_ = match impl_.of_trait {
29252925
Some(t) => {
2926-
if renamed.is_some() {
2926+
if is_inlined {
29272927
return vec![Item::from_def_id_and_parts(
29282928
def_id.to_def_id(),
29292929
None,

src/librustdoc/passes/propagate_doc_cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct CfgPropagator<'a, 'tcx> {
2929
cx: &'a mut DocContext<'tcx>,
3030
cfg_info: CfgInfo,
3131

32-
/// To ensure the `doc_cfg` feature works with how `rustdoc` handles impl, we need to store
32+
/// To ensure the `doc_cfg` feature works with how `rustdoc` handles impls, we need to store
3333
/// the `cfg` info of `impl`s placeholder to use them later on the "real" impl item.
3434
impl_cfg_info: FxHashMap<ItemId, CfgInfo>,
3535
}
@@ -85,7 +85,7 @@ impl DocFolder for CfgPropagator<'_, '_> {
8585
let old_cfg_info = self.cfg_info.clone();
8686

8787
// If we have an impl, we check if it has an associated `cfg` "context", and if so we will
88-
// use this context instead of the actual (wrong) one.
88+
// use that context instead of the actual (wrong) one.
8989
if let ItemKind::ImplItem(_) = item.kind
9090
&& let Some(cfg_info) = self.impl_cfg_info.remove(&item.item_id)
9191
{

src/librustdoc/visit_ast.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
372372
&& !inherits_doc_hidden(tcx, item_def_id, None)
373373
}
374374

375+
#[inline]
376+
fn add_impl_to_current_mod(&mut self, item: &'tcx hir::Item<'_>, impl_: hir::Impl<'_>) {
377+
self.add_to_current_mod(
378+
item,
379+
// The symbol here is used as a "sentinel" value and has no meaning in
380+
// itself. It just tells that this is an inlined impl and that it should not
381+
// be cleaned as a normal `ImplItem` but instead as a `PlaceholderImplItem`.
382+
// It's to ensure that `doc_cfg` inheritance works as expected.
383+
if impl_.of_trait.is_none() { None } else { Some(rustc_span::symbol::kw::Impl) },
384+
None,
385+
);
386+
}
387+
375388
#[inline]
376389
fn add_to_current_mod(
377390
&mut self,
@@ -427,19 +440,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
427440
// Bar::bar();
428441
// ```
429442
if let hir::ItemKind::Impl(impl_) = item.kind {
430-
self.add_to_current_mod(
431-
item,
432-
// The symbol here is used as a "sentinel" value and has no meaning in
433-
// itself. It just tells that this is an inlined impl and that it should not
434-
// be cleaned as a normal `ImplItem` but instead as a `PlaceholderImplItem`.
435-
// It's to ensure that `doc_cfg` inheritance works as expected.
436-
if impl_.of_trait.is_none() {
437-
None
438-
} else {
439-
Some(rustc_span::symbol::kw::Impl)
440-
},
441-
None,
442-
);
443+
self.add_impl_to_current_mod(item, impl_);
443444
}
444445
return;
445446
}
@@ -541,19 +542,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
541542
// Don't duplicate impls when inlining, we'll pick
542543
// them up regardless of where they're located.
543544
if !self.inlining {
544-
self.add_to_current_mod(
545-
item,
546-
// The symbol here is used as a "sentinel" value and has no meaning in
547-
// itself. It just tells that this is an inlined impl and that it should not
548-
// be cleaned as a normal `ImplItem` but instead as a `PlaceholderImplItem`.
549-
// It's to ensure that `doc_cfg` inheritance works as expected.
550-
if impl_.of_trait.is_none() {
551-
None
552-
} else {
553-
Some(rustc_span::symbol::kw::Impl)
554-
},
555-
None,
556-
);
545+
self.add_impl_to_current_mod(item, impl_);
557546
}
558547
}
559548
}

0 commit comments

Comments
 (0)