Skip to content

Commit b5c8eea

Browse files
Put clean::Trait extra information into a new struct to make it more coherent
1 parent fa51c0f commit b5c8eea

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

src/librustdoc/clean/inline.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,12 @@ crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
624624
debug!("record_extern_trait: {:?}", did);
625625
let trait_ = build_external_trait(cx, did);
626626

627-
cx.external_traits
628-
.borrow_mut()
629-
.insert(did, (trait_, clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight)));
627+
cx.external_traits.borrow_mut().insert(
628+
did,
629+
clean::TraitWithExtraInfo {
630+
trait_,
631+
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight),
632+
},
633+
);
630634
cx.active_extern_traits.remove(&did);
631635
}

src/librustdoc/clean/types.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,18 @@ crate struct Crate {
5757
crate primitives: Vec<(DefId, PrimitiveType)>,
5858
// These are later on moved into `CACHEKEY`, leaving the map empty.
5959
// Only here so that they can be filtered through the rustdoc passes.
60-
crate external_traits: Rc<RefCell<FxHashMap<DefId, (Trait, bool)>>>,
60+
crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
6161
crate masked_crates: FxHashSet<CrateNum>,
6262
crate collapsed: bool,
6363
}
6464

65+
/// This struct is used to wrap additional information added by rustdoc on a `trait` item.
66+
#[derive(Clone, Debug)]
67+
crate struct TraitWithExtraInfo {
68+
crate trait_: Trait,
69+
crate is_spotlight: bool,
70+
}
71+
6572
#[derive(Clone, Debug)]
6673
crate struct ExternalCrate {
6774
crate name: Symbol,

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ crate struct DocContext<'tcx> {
5555
/// Later on moved into `cache`
5656
crate renderinfo: RenderInfo,
5757
/// Later on moved through `clean::Crate` into `cache`
58-
crate external_traits: Rc<RefCell<FxHashMap<DefId, (clean::Trait, bool)>>>,
58+
crate external_traits: Rc<RefCell<FxHashMap<DefId, clean::TraitWithExtraInfo>>>,
5959
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
6060
/// the same time.
6161
crate active_extern_traits: FxHashSet<DefId>,

src/librustdoc/fold.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ crate trait DocFolder: Sized {
9191

9292
{
9393
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
94-
for (k, (mut v, is_spotlight)) in external_traits {
95-
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
96-
c.external_traits.borrow_mut().insert(k, (v, is_spotlight));
94+
for (k, mut v) in external_traits {
95+
v.trait_.items =
96+
v.trait_.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
97+
c.external_traits.borrow_mut().insert(k, v);
9798
}
9899
}
99100
c

src/librustdoc/formats/cache.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ crate struct Cache {
6565
/// Implementations of a crate should inherit the documentation of the
6666
/// parent trait if no extra documentation is specified, and default methods
6767
/// should show up in documentation about trait implementations.
68-
///
69-
/// The `bool` parameter is about if the trait is `spotlight`.
70-
crate traits: FxHashMap<DefId, (clean::Trait, bool)>,
68+
crate traits: FxHashMap<DefId, clean::TraitWithExtraInfo>,
7169

7270
/// When rendering traits, it's often useful to be able to list all
7371
/// implementors of the trait, and this mapping is exactly, that: a mapping
@@ -251,8 +249,12 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
251249
// Propagate a trait method's documentation to all implementors of the
252250
// trait.
253251
if let clean::TraitItem(ref t) = *item.kind {
254-
self.cache.traits.entry(item.def_id).or_insert_with(|| {
255-
(t.clone(), clean::utils::has_doc_flag(tcx.get_attrs(item.def_id), sym::spotlight))
252+
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
253+
trait_: t.clone(),
254+
is_spotlight: clean::utils::has_doc_flag(
255+
tcx.get_attrs(item.def_id),
256+
sym::spotlight,
257+
),
256258
});
257259
}
258260

src/librustdoc/html/render/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
36883688
for i in impls {
36893689
let impl_ = i.inner_impl();
36903690
if impl_.trait_.def_id().map_or(false, |d| {
3691-
cache.traits.get(&d).map(|(_, is_spotlight)| *is_spotlight).unwrap_or(false)
3691+
cache.traits.get(&d).map(|t| t.is_spotlight).unwrap_or(false)
36923692
}) {
36933693
if out.is_empty() {
36943694
write!(
@@ -3980,7 +3980,7 @@ fn render_impl(
39803980
false,
39813981
outer_version,
39823982
outer_const_version,
3983-
trait_.map(|(t, _)| t),
3983+
trait_.map(|t| &t.trait_),
39843984
show_def_docs,
39853985
);
39863986
}
@@ -4025,11 +4025,11 @@ fn render_impl(
40254025
// We don't emit documentation for default items if they appear in the
40264026
// Implementations on Foreign Types or Implementors sections.
40274027
if show_default_items {
4028-
if let Some((t, _)) = trait_ {
4028+
if let Some(t) = trait_ {
40294029
render_default_items(
40304030
w,
40314031
cx,
4032-
t,
4032+
&t.trait_,
40334033
&i.inner_impl(),
40344034
&i.impl_item,
40354035
render_mode,

src/librustdoc/json/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ impl JsonRenderer<'tcx> {
8484
Rc::clone(&self.cache)
8585
.traits
8686
.iter()
87-
.filter_map(|(&id, (trait_item, _))| {
87+
.filter_map(|(&id, trait_item)| {
8888
// only need to synthesize items for external traits
8989
if !id.is_local() {
90+
let trait_item = &trait_item.trait_;
9091
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
9192
Some((
9293
from_def_id(id),

0 commit comments

Comments
 (0)