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