Skip to content

Commit

Permalink
rustdoc: pass owner item of generics to cleaning functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Feb 28, 2024
1 parent 1c28a2c commit 438ca19
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 63 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ where
self.cx,
tcx.generics_of(item_def_id),
ty::GenericPredicates::default(),
item_def_id,
);
let params = raw_generics.params;

Expand Down Expand Up @@ -456,6 +457,7 @@ where
self.cx,
tcx.generics_of(item_def_id),
tcx.explicit_predicates_of(item_def_id),
item_def_id,
);
let mut generic_params = raw_generics.params;

Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
cx,
cx.tcx.generics_of(impl_def_id),
cx.tcx.explicit_predicates_of(impl_def_id),
impl_def_id,
),
// FIXME(eddyb) compute both `trait_` and `for_` from
// the post-inference `trait_ref`, as it's more accurate.
Expand Down
30 changes: 19 additions & 11 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
.collect();

let predicates = cx.tcx.predicates_of(did);
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates, did);
let generics = filter_non_trait_generics(did, generics);
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
Expand All @@ -282,8 +282,12 @@ pub(crate) fn build_function<'tcx>(
) -> Box<clean::Function> {
let sig = cx.tcx.fn_sig(def_id).instantiate_identity();
// The generics need to be cleaned before the signature.
let mut generics =
clean_ty_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id));
let mut generics = clean_ty_generics(
cx,
cx.tcx.generics_of(def_id),
cx.tcx.explicit_predicates_of(def_id),
def_id,
);
let bound_vars = clean_bound_vars(sig.bound_vars());

// At the time of writing early & late-bound params are stored separately in rustc,
Expand Down Expand Up @@ -315,7 +319,7 @@ fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {
let predicates = cx.tcx.explicit_predicates_of(did);

clean::Enum {
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates, did),
variants: cx.tcx.adt_def(did).variants().iter().map(|v| clean_variant_def(v, cx)).collect(),
}
}
Expand All @@ -326,7 +330,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {

clean::Struct {
ctor_kind: variant.ctor_kind(),
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates, did),
fields: variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect(),
}
}
Expand All @@ -335,7 +339,7 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
let predicates = cx.tcx.explicit_predicates_of(did);
let variant = cx.tcx.adt_def(did).non_enum_variant();

let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates, did);
let fields = variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect();
clean::Union { generics, fields }
}
Expand All @@ -352,7 +356,7 @@ fn build_type_alias(

Box::new(clean::TypeAlias {
type_,
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates, did),
inner_type,
item_type: None,
})
Expand Down Expand Up @@ -530,7 +534,7 @@ pub(crate) fn build_impl(
})
.map(|item| clean_impl_item(item, cx))
.collect::<Vec<_>>(),
clean_generics(impl_.generics, cx),
clean_generics(impl_.generics, cx, did),
),
None => (
tcx.associated_items(did)
Expand Down Expand Up @@ -558,7 +562,7 @@ pub(crate) fn build_impl(
.map(|item| clean_middle_assoc_item(item, cx))
.collect::<Vec<_>>(),
clean::enter_impl_trait(cx, |cx| {
clean_ty_generics(cx, tcx.generics_of(did), predicates)
clean_ty_generics(cx, tcx.generics_of(did), predicates, did)
}),
),
};
Expand Down Expand Up @@ -716,8 +720,12 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
}

fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
let mut generics =
clean_ty_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id));
let mut generics = clean_ty_generics(
cx,
cx.tcx.generics_of(def_id),
cx.tcx.explicit_predicates_of(def_id),
def_id,
);
clean::simplify::move_bounds_to_generic_parameters(&mut generics);

clean::Constant {
Expand Down
Loading

0 comments on commit 438ca19

Please sign in to comment.