Skip to content

[wip] rustdoc: variances #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 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, // FIXME: ofc its DefKind is not an impl confusing the variance compution
);
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, // FIXME: ofc its DefKind is not an impl confusing the variance compution
);
let mut generic_params = raw_generics.params;

Expand Down Expand Up @@ -630,19 +632,19 @@ where
existing_predicates.extend(final_bounds);

for param in generic_params.iter_mut() {
match param.kind {
GenericParamDefKind::Type { ref mut default, ref mut bounds, .. } => {
match &mut param.kind {
GenericParamDefKind::Type(ty_param) => {
// We never want something like `impl<T=Foo>`.
default.take();
ty_param.default.take();
let generic_ty = Type::Generic(param.name);
if !has_sized.contains(&generic_ty) {
bounds.insert(0, GenericBound::maybe_sized(self.cx));
ty_param.bounds.insert(0, GenericBound::maybe_sized(self.cx));
}
}
GenericParamDefKind::Lifetime { .. } => {}
GenericParamDefKind::Const { ref mut default, .. } => {
GenericParamDefKind::Const(ct_param) => {
// We never want something like `impl<const N: usize = 10>`
default.take();
ct_param.default.take();
}
}
}
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