Skip to content

Commit ffa7733

Browse files
committed
Auto merge of #99598 - GuillaumeGomez:clean-trait-fields-on-demand, r=notriddle
Make some clean::Trait fields computation on demand r? `@notriddle`
2 parents 22d25f2 + edb9add commit ffa7733

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

src/librustdoc/clean/inline.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
214214
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
215215
let generics = filter_non_trait_generics(did, generics);
216216
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
217-
let is_auto = cx.tcx.trait_is_auto(did);
218-
clean::Trait {
219-
unsafety: cx.tcx.trait_def(did).unsafety,
220-
generics,
221-
items: trait_items,
222-
bounds: supertrait_bounds,
223-
is_auto,
224-
}
217+
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
225218
}
226219

227220
fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean::Function {

src/librustdoc/clean/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1972,15 +1972,14 @@ fn clean_maybe_renamed_item<'tcx>(
19721972
source: display_macro_source(cx, name, macro_def, def_id, ty_vis),
19731973
})
19741974
}
1975-
ItemKind::Trait(is_auto, unsafety, generics, bounds, item_ids) => {
1975+
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
19761976
let items =
19771977
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
19781978
TraitItem(Trait {
1979-
unsafety,
1979+
def_id,
19801980
items,
19811981
generics: generics.clean(cx),
19821982
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
1983-
is_auto: is_auto.clean(cx),
19841983
})
19851984
}
19861985
ItemKind::ExternCrate(orig_name) => {

src/librustdoc/clean/types.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,19 @@ impl FnRetTy {
15131513

15141514
#[derive(Clone, Debug)]
15151515
pub(crate) struct Trait {
1516-
pub(crate) unsafety: hir::Unsafety,
1516+
pub(crate) def_id: DefId,
15171517
pub(crate) items: Vec<Item>,
15181518
pub(crate) generics: Generics,
15191519
pub(crate) bounds: Vec<GenericBound>,
1520-
pub(crate) is_auto: bool,
1520+
}
1521+
1522+
impl Trait {
1523+
pub(crate) fn is_auto(&self, tcx: TyCtxt<'_>) -> bool {
1524+
tcx.trait_is_auto(self.def_id)
1525+
}
1526+
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
1527+
tcx.trait_def(self.def_id).unsafety
1528+
}
15211529
}
15221530

15231531
#[derive(Clone, Debug)]

src/librustdoc/core.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ pub(crate) fn run_global_ctxt(
390390
//
391391
// Note that in case of `#![no_core]`, the trait is not available.
392392
if let Some(sized_trait_did) = ctxt.tcx.lang_items().sized_trait() {
393-
let mut sized_trait = build_external_trait(&mut ctxt, sized_trait_did);
394-
sized_trait.is_auto = true;
393+
let sized_trait = build_external_trait(&mut ctxt, sized_trait_did);
395394
ctxt.external_traits
396395
.borrow_mut()
397396
.insert(sized_trait_did, TraitWithExtraInfo { trait_: sized_trait, is_notable: false });

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
22952295
sidebar_assoc_items(cx, buf, it);
22962296

22972297
print_sidebar_title(buf, "implementors", "Implementors");
2298-
if t.is_auto {
2298+
if t.is_auto(cx.tcx()) {
22992299
print_sidebar_title(buf, "synthetic-implementors", "Auto Implementors");
23002300
}
23012301

src/librustdoc/html/render/print_item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
548548
w,
549549
"{}{}{}trait {}{}{}",
550550
it.visibility.print_with_space(it.item_id, cx),
551-
t.unsafety.print_with_space(),
552-
if t.is_auto { "auto " } else { "" },
551+
t.unsafety(cx.tcx()).print_with_space(),
552+
if t.is_auto(cx.tcx()) { "auto " } else { "" },
553553
it.name.unwrap(),
554554
t.generics.print(cx),
555555
bounds
@@ -883,7 +883,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
883883
}
884884
w.write_str("</div>");
885885

886-
if t.is_auto {
886+
if t.is_auto(cx.tcx()) {
887887
write_small_section_header(
888888
w,
889889
"synthetic-implementors",
@@ -912,7 +912,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
912912
"<div class=\"item-list\" id=\"implementors-list\"></div>",
913913
);
914914

915-
if t.is_auto {
915+
if t.is_auto(cx.tcx()) {
916916
write_small_section_header(
917917
w,
918918
"synthetic-implementors",

src/librustdoc/json/conversions.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,12 @@ impl FromWithTcx<clean::FnDecl> for FnDecl {
554554

555555
impl FromWithTcx<clean::Trait> for Trait {
556556
fn from_tcx(trait_: clean::Trait, tcx: TyCtxt<'_>) -> Self {
557-
let clean::Trait { unsafety, items, generics, bounds, is_auto } = trait_;
557+
let is_auto = trait_.is_auto(tcx);
558+
let is_unsafe = trait_.unsafety(tcx) == rustc_hir::Unsafety::Unsafe;
559+
let clean::Trait { items, generics, bounds, .. } = trait_;
558560
Trait {
559561
is_auto,
560-
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
562+
is_unsafe,
561563
items: ids(items, tcx),
562564
generics: generics.into_tcx(tcx),
563565
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),

0 commit comments

Comments
 (0)