Put clean::Trait extra information into a new struct to make it more coherent
This commit is contained in:
parent
fa51c0f472
commit
b5c8eea55d
7 changed files with 33 additions and 18 deletions
|
@ -624,8 +624,12 @@ crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
|
||||||
debug!("record_extern_trait: {:?}", did);
|
debug!("record_extern_trait: {:?}", did);
|
||||||
let trait_ = build_external_trait(cx, did);
|
let trait_ = build_external_trait(cx, did);
|
||||||
|
|
||||||
cx.external_traits
|
cx.external_traits.borrow_mut().insert(
|
||||||
.borrow_mut()
|
did,
|
||||||
.insert(did, (trait_, clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight)));
|
clean::TraitWithExtraInfo {
|
||||||
|
trait_,
|
||||||
|
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight),
|
||||||
|
},
|
||||||
|
);
|
||||||
cx.active_extern_traits.remove(&did);
|
cx.active_extern_traits.remove(&did);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,18 @@ crate struct Crate {
|
||||||
crate primitives: Vec<(DefId, PrimitiveType)>,
|
crate primitives: Vec<(DefId, PrimitiveType)>,
|
||||||
// These are later on moved into `CACHEKEY`, leaving the map empty.
|
// These are later on moved into `CACHEKEY`, leaving the map empty.
|
||||||
// Only here so that they can be filtered through the rustdoc passes.
|
// Only here so that they can be filtered through the rustdoc passes.
|
||||||
crate external_traits: Rc<RefCell<FxHashMap<DefId, (Trait, bool)>>>,
|
crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
|
||||||
crate masked_crates: FxHashSet<CrateNum>,
|
crate masked_crates: FxHashSet<CrateNum>,
|
||||||
crate collapsed: bool,
|
crate collapsed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This struct is used to wrap additional information added by rustdoc on a `trait` item.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
crate struct TraitWithExtraInfo {
|
||||||
|
crate trait_: Trait,
|
||||||
|
crate is_spotlight: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct ExternalCrate {
|
crate struct ExternalCrate {
|
||||||
crate name: Symbol,
|
crate name: Symbol,
|
||||||
|
|
|
@ -55,7 +55,7 @@ crate struct DocContext<'tcx> {
|
||||||
/// Later on moved into `cache`
|
/// Later on moved into `cache`
|
||||||
crate renderinfo: RenderInfo,
|
crate renderinfo: RenderInfo,
|
||||||
/// Later on moved through `clean::Crate` into `cache`
|
/// Later on moved through `clean::Crate` into `cache`
|
||||||
crate external_traits: Rc<RefCell<FxHashMap<DefId, (clean::Trait, bool)>>>,
|
crate external_traits: Rc<RefCell<FxHashMap<DefId, clean::TraitWithExtraInfo>>>,
|
||||||
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
|
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
|
||||||
/// the same time.
|
/// the same time.
|
||||||
crate active_extern_traits: FxHashSet<DefId>,
|
crate active_extern_traits: FxHashSet<DefId>,
|
||||||
|
|
|
@ -91,9 +91,10 @@ crate trait DocFolder: Sized {
|
||||||
|
|
||||||
{
|
{
|
||||||
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
|
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
|
||||||
for (k, (mut v, is_spotlight)) in external_traits {
|
for (k, mut v) in external_traits {
|
||||||
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
|
v.trait_.items =
|
||||||
c.external_traits.borrow_mut().insert(k, (v, is_spotlight));
|
v.trait_.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
|
||||||
|
c.external_traits.borrow_mut().insert(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c
|
c
|
||||||
|
|
|
@ -65,9 +65,7 @@ crate struct Cache {
|
||||||
/// Implementations of a crate should inherit the documentation of the
|
/// Implementations of a crate should inherit the documentation of the
|
||||||
/// parent trait if no extra documentation is specified, and default methods
|
/// parent trait if no extra documentation is specified, and default methods
|
||||||
/// should show up in documentation about trait implementations.
|
/// should show up in documentation about trait implementations.
|
||||||
///
|
crate traits: FxHashMap<DefId, clean::TraitWithExtraInfo>,
|
||||||
/// The `bool` parameter is about if the trait is `spotlight`.
|
|
||||||
crate traits: FxHashMap<DefId, (clean::Trait, bool)>,
|
|
||||||
|
|
||||||
/// When rendering traits, it's often useful to be able to list all
|
/// When rendering traits, it's often useful to be able to list all
|
||||||
/// implementors of the trait, and this mapping is exactly, that: a mapping
|
/// implementors of the trait, and this mapping is exactly, that: a mapping
|
||||||
|
@ -251,8 +249,12 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||||
// Propagate a trait method's documentation to all implementors of the
|
// Propagate a trait method's documentation to all implementors of the
|
||||||
// trait.
|
// trait.
|
||||||
if let clean::TraitItem(ref t) = *item.kind {
|
if let clean::TraitItem(ref t) = *item.kind {
|
||||||
self.cache.traits.entry(item.def_id).or_insert_with(|| {
|
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
|
||||||
(t.clone(), clean::utils::has_doc_flag(tcx.get_attrs(item.def_id), sym::spotlight))
|
trait_: t.clone(),
|
||||||
|
is_spotlight: clean::utils::has_doc_flag(
|
||||||
|
tcx.get_attrs(item.def_id),
|
||||||
|
sym::spotlight,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3688,7 +3688,7 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
|
||||||
for i in impls {
|
for i in impls {
|
||||||
let impl_ = i.inner_impl();
|
let impl_ = i.inner_impl();
|
||||||
if impl_.trait_.def_id().map_or(false, |d| {
|
if impl_.trait_.def_id().map_or(false, |d| {
|
||||||
cache.traits.get(&d).map(|(_, is_spotlight)| *is_spotlight).unwrap_or(false)
|
cache.traits.get(&d).map(|t| t.is_spotlight).unwrap_or(false)
|
||||||
}) {
|
}) {
|
||||||
if out.is_empty() {
|
if out.is_empty() {
|
||||||
write!(
|
write!(
|
||||||
|
@ -3980,7 +3980,7 @@ fn render_impl(
|
||||||
false,
|
false,
|
||||||
outer_version,
|
outer_version,
|
||||||
outer_const_version,
|
outer_const_version,
|
||||||
trait_.map(|(t, _)| t),
|
trait_.map(|t| &t.trait_),
|
||||||
show_def_docs,
|
show_def_docs,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4025,11 +4025,11 @@ fn render_impl(
|
||||||
// We don't emit documentation for default items if they appear in the
|
// We don't emit documentation for default items if they appear in the
|
||||||
// Implementations on Foreign Types or Implementors sections.
|
// Implementations on Foreign Types or Implementors sections.
|
||||||
if show_default_items {
|
if show_default_items {
|
||||||
if let Some((t, _)) = trait_ {
|
if let Some(t) = trait_ {
|
||||||
render_default_items(
|
render_default_items(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
t,
|
&t.trait_,
|
||||||
&i.inner_impl(),
|
&i.inner_impl(),
|
||||||
&i.impl_item,
|
&i.impl_item,
|
||||||
render_mode,
|
render_mode,
|
||||||
|
|
|
@ -84,9 +84,10 @@ impl JsonRenderer<'tcx> {
|
||||||
Rc::clone(&self.cache)
|
Rc::clone(&self.cache)
|
||||||
.traits
|
.traits
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(&id, (trait_item, _))| {
|
.filter_map(|(&id, trait_item)| {
|
||||||
// only need to synthesize items for external traits
|
// only need to synthesize items for external traits
|
||||||
if !id.is_local() {
|
if !id.is_local() {
|
||||||
|
let trait_item = &trait_item.trait_;
|
||||||
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
|
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
|
||||||
Some((
|
Some((
|
||||||
from_def_id(id),
|
from_def_id(id),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue