Make some clean::Trait fields computation on demand
This commit is contained in:
parent
d60d88fe5c
commit
edb9add193
@ -214,14 +214,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
|
||||
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
|
||||
let generics = filter_non_trait_generics(did, generics);
|
||||
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
|
||||
let is_auto = cx.tcx.trait_is_auto(did);
|
||||
clean::Trait {
|
||||
unsafety: cx.tcx.trait_def(did).unsafety,
|
||||
generics,
|
||||
items: trait_items,
|
||||
bounds: supertrait_bounds,
|
||||
is_auto,
|
||||
}
|
||||
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
|
||||
}
|
||||
|
||||
fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean::Function {
|
||||
|
@ -1972,15 +1972,14 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||
source: display_macro_source(cx, name, macro_def, def_id, ty_vis),
|
||||
})
|
||||
}
|
||||
ItemKind::Trait(is_auto, unsafety, generics, bounds, item_ids) => {
|
||||
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
|
||||
let items =
|
||||
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
|
||||
TraitItem(Trait {
|
||||
unsafety,
|
||||
def_id,
|
||||
items,
|
||||
generics: generics.clean(cx),
|
||||
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
|
||||
is_auto: is_auto.clean(cx),
|
||||
})
|
||||
}
|
||||
ItemKind::ExternCrate(orig_name) => {
|
||||
|
@ -1514,11 +1514,19 @@ impl FnRetTy {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct Trait {
|
||||
pub(crate) unsafety: hir::Unsafety,
|
||||
pub(crate) def_id: DefId,
|
||||
pub(crate) items: Vec<Item>,
|
||||
pub(crate) generics: Generics,
|
||||
pub(crate) bounds: Vec<GenericBound>,
|
||||
pub(crate) is_auto: bool,
|
||||
}
|
||||
|
||||
impl Trait {
|
||||
pub(crate) fn is_auto(&self, tcx: TyCtxt<'_>) -> bool {
|
||||
tcx.trait_is_auto(self.def_id)
|
||||
}
|
||||
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
|
||||
tcx.trait_def(self.def_id).unsafety
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -390,8 +390,7 @@ pub(crate) fn run_global_ctxt(
|
||||
//
|
||||
// Note that in case of `#![no_core]`, the trait is not available.
|
||||
if let Some(sized_trait_did) = ctxt.tcx.lang_items().sized_trait() {
|
||||
let mut sized_trait = build_external_trait(&mut ctxt, sized_trait_did);
|
||||
sized_trait.is_auto = true;
|
||||
let sized_trait = build_external_trait(&mut ctxt, sized_trait_did);
|
||||
ctxt.external_traits
|
||||
.borrow_mut()
|
||||
.insert(sized_trait_did, TraitWithExtraInfo { trait_: sized_trait, is_notable: false });
|
||||
|
@ -2295,7 +2295,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
|
||||
sidebar_assoc_items(cx, buf, it);
|
||||
|
||||
print_sidebar_title(buf, "implementors", "Implementors");
|
||||
if t.is_auto {
|
||||
if t.is_auto(cx.tcx()) {
|
||||
print_sidebar_title(buf, "synthetic-implementors", "Auto Implementors");
|
||||
}
|
||||
|
||||
|
@ -548,8 +548,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||
w,
|
||||
"{}{}{}trait {}{}{}",
|
||||
it.visibility.print_with_space(it.item_id, cx),
|
||||
t.unsafety.print_with_space(),
|
||||
if t.is_auto { "auto " } else { "" },
|
||||
t.unsafety(cx.tcx()).print_with_space(),
|
||||
if t.is_auto(cx.tcx()) { "auto " } else { "" },
|
||||
it.name.unwrap(),
|
||||
t.generics.print(cx),
|
||||
bounds
|
||||
@ -883,7 +883,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||
}
|
||||
w.write_str("</div>");
|
||||
|
||||
if t.is_auto {
|
||||
if t.is_auto(cx.tcx()) {
|
||||
write_small_section_header(
|
||||
w,
|
||||
"synthetic-implementors",
|
||||
@ -912,7 +912,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||
"<div class=\"item-list\" id=\"implementors-list\"></div>",
|
||||
);
|
||||
|
||||
if t.is_auto {
|
||||
if t.is_auto(cx.tcx()) {
|
||||
write_small_section_header(
|
||||
w,
|
||||
"synthetic-implementors",
|
||||
|
@ -554,10 +554,12 @@ impl FromWithTcx<clean::FnDecl> for FnDecl {
|
||||
|
||||
impl FromWithTcx<clean::Trait> for Trait {
|
||||
fn from_tcx(trait_: clean::Trait, tcx: TyCtxt<'_>) -> Self {
|
||||
let clean::Trait { unsafety, items, generics, bounds, is_auto } = trait_;
|
||||
let is_auto = trait_.is_auto(tcx);
|
||||
let is_unsafe = trait_.unsafety(tcx) == rustc_hir::Unsafety::Unsafe;
|
||||
let clean::Trait { items, generics, bounds, .. } = trait_;
|
||||
Trait {
|
||||
is_auto,
|
||||
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
|
||||
is_unsafe,
|
||||
items: ids(items, tcx),
|
||||
generics: generics.into_tcx(tcx),
|
||||
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user