Skip to content

Commit

Permalink
Auto merge of rust-lang#99598 - GuillaumeGomez:clean-trait-fields-on-…
Browse files Browse the repository at this point in the history
…demand, r=notriddle

Make some clean::Trait fields computation on demand

r? `@notriddle`
  • Loading branch information
bors committed Jul 22, 2022
2 parents 22d25f2 + edb9add commit ffa7733
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
9 changes: 1 addition & 8 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 10 additions & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,11 +1513,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)]
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ffa7733

Please sign in to comment.