Skip to content
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

[PoC] Rustdoc move hir cleaners #18

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 5 additions & 8 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use thin_vec::ThinVec;

use crate::clean::{self, simplify, Lifetime};
use crate::clean::{
clean_generic_param_def, clean_middle_ty, clean_predicate, clean_trait_ref_with_constraints,
clean_ty_generics,
clean_generic_param_def, clean_generics, clean_predicate, clean_trait_ref_with_constraints,
clean_ty,
};
use crate::core::DocContext;

Expand Down Expand Up @@ -102,11 +102,8 @@ fn synthesize_auto_trait_impl<'tcx>(
// Instead, we generate `impl !Send for Foo<T>`, which better
// expresses the fact that `Foo<T>` never implements `Send`,
// regardless of the choice of `T`.
let mut generics = clean_ty_generics(
cx,
tcx.generics_of(item_def_id),
ty::GenericPredicates::default(),
);
let mut generics =
clean_generics(cx, tcx.generics_of(item_def_id), ty::GenericPredicates::default());
generics.where_predicates.clear();

(generics, ty::ImplPolarity::Negative)
Expand All @@ -122,7 +119,7 @@ fn synthesize_auto_trait_impl<'tcx>(
safety: hir::Safety::Safe,
generics,
trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())),
for_: clean_middle_ty(ty::Binder::dummy(ty), cx, None, None),
for_: clean_ty(ty::Binder::dummy(ty), cx, None, None),
items: Vec::new(),
polarity,
kind: clean::ImplKind::Auto,
Expand Down
17 changes: 5 additions & 12 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use thin_vec::ThinVec;

use crate::clean;
use crate::clean::{
clean_middle_assoc_item, clean_middle_ty, clean_trait_ref_with_constraints, clean_ty_generics,
};
use crate::clean::{clean_assoc_item, clean_generics, clean_trait_ref_with_constraints, clean_ty};
use crate::core::DocContext;

#[instrument(level = "debug", skip(cx))]
Expand Down Expand Up @@ -88,7 +86,7 @@ pub(crate) fn synthesize_blanket_impls(
item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: Box::new(clean::ImplItem(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics: clean_ty_generics(
generics: clean_generics(
cx,
tcx.generics_of(impl_def_id),
tcx.explicit_predicates_of(impl_def_id),
Expand All @@ -100,20 +98,15 @@ pub(crate) fn synthesize_blanket_impls(
ty::Binder::dummy(trait_ref.instantiate_identity()),
ThinVec::new(),
)),
for_: clean_middle_ty(
ty::Binder::dummy(ty.instantiate_identity()),
cx,
None,
None,
),
for_: clean_ty(ty::Binder::dummy(ty.instantiate_identity()), cx, None, None),
items: tcx
.associated_items(impl_def_id)
.in_definition_order()
.filter(|item| !item.is_impl_trait_in_trait())
.map(|item| clean_middle_assoc_item(item, cx))
.map(|item| clean_assoc_item(item, cx))
.collect(),
polarity: ty::ImplPolarity::Positive,
kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty(
kind: clean::ImplKind::Blanket(Box::new(clean_ty(
ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
cx,
None,
Expand Down
53 changes: 23 additions & 30 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};

use crate::clean::{
self, clean_bound_vars, clean_generics, clean_impl_item, clean_middle_assoc_item,
clean_middle_field, clean_middle_ty, clean_poly_fn_sig, clean_trait_ref_with_constraints,
clean_ty, clean_ty_alias_inner_type, clean_ty_generics, clean_variant_def, utils, Attributes,
AttributesExt, ImplKind, ItemId, Type,
self, clean_assoc_item, clean_bound_vars, clean_field, clean_generics, clean_poly_fn_sig,
clean_trait_ref_with_constraints, clean_ty, clean_ty_alias_inner_type, clean_variant_def,
local, utils, Attributes, AttributesExt, ImplKind, ItemId, Type,
};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;
Expand Down Expand Up @@ -281,11 +280,11 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
.associated_items(did)
.in_definition_order()
.filter(|item| !item.is_impl_trait_in_trait())
.map(|item| clean_middle_assoc_item(item, cx))
.map(|item| clean_assoc_item(item, cx))
.collect();

let predicates = cx.tcx.predicates_of(did);
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
let generics = clean_generics(cx, cx.tcx.generics_of(did), predicates);
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 @@ -298,7 +297,7 @@ pub(crate) fn build_function<'tcx>(
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));
clean_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(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 @@ -330,7 +329,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_generics(cx, cx.tcx.generics_of(did), predicates),
variants: cx.tcx.adt_def(did).variants().iter().map(|v| clean_variant_def(v, cx)).collect(),
}
}
Expand All @@ -341,17 +340,17 @@ 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),
fields: variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect(),
generics: clean_generics(cx, cx.tcx.generics_of(did), predicates),
fields: variant.fields.iter().map(|x| clean_field(x, cx)).collect(),
}
}

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 fields = variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect();
let generics = clean_generics(cx, cx.tcx.generics_of(did), predicates);
let fields = variant.fields.iter().map(|x| clean_field(x, cx)).collect();
clean::Union { generics, fields }
}

Expand All @@ -362,12 +361,12 @@ fn build_type_alias(
) -> Box<clean::TypeAlias> {
let predicates = cx.tcx.explicit_predicates_of(did);
let ty = cx.tcx.type_of(did).instantiate_identity();
let type_ = clean_middle_ty(ty::Binder::dummy(ty), cx, Some(did), None);
let type_ = clean_ty(ty::Binder::dummy(ty), cx, Some(did), None);
let inner_type = clean_ty_alias_inner_type(ty, cx, ret);

Box::new(clean::TypeAlias {
type_,
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
generics: clean_generics(cx, cx.tcx.generics_of(did), predicates),
inner_type,
item_type: None,
})
Expand Down Expand Up @@ -477,8 +476,8 @@ pub(crate) fn build_impl(
};

let for_ = match &impl_item {
Some(impl_) => clean_ty(impl_.self_ty, cx),
None => clean_middle_ty(
Some(impl_) => local::clean_ty(impl_.self_ty, cx),
None => clean_ty(
ty::Binder::dummy(tcx.type_of(did).instantiate_identity()),
cx,
Some(did),
Expand Down Expand Up @@ -533,9 +532,9 @@ pub(crate) fn build_impl(
true
}
})
.map(|item| clean_impl_item(item, cx))
.map(|item| local::clean_impl_item(item, cx))
.collect::<Vec<_>>(),
clean_generics(impl_.generics, cx),
local::clean_generics(impl_.generics, cx),
),
None => (
tcx.associated_items(did)
Expand All @@ -560,11 +559,9 @@ pub(crate) fn build_impl(
item.visibility(tcx).is_public()
}
})
.map(|item| clean_middle_assoc_item(item, cx))
.map(|item| clean_assoc_item(item, cx))
.collect::<Vec<_>>(),
clean::enter_impl_trait(cx, |cx| {
clean_ty_generics(cx, tcx.generics_of(did), predicates)
}),
clean::enter_impl_trait(cx, |cx| clean_generics(cx, tcx.generics_of(did), predicates)),
),
};
let polarity = tcx.impl_polarity(did);
Expand Down Expand Up @@ -725,20 +722,16 @@ fn build_const_item(
def_id: DefId,
) -> (clean::Generics, clean::Type, clean::Constant) {
let mut generics =
clean_ty_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id));
clean_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id));
clean::simplify::move_bounds_to_generic_parameters(&mut generics);
let ty = clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()),
cx,
None,
None,
);
let ty =
clean_ty(ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()), cx, None, None);
(generics, ty, clean::Constant { kind: clean::ConstantKind::Extern { def_id } })
}

fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
clean::Static {
type_: clean_middle_ty(
type_: clean_ty(
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity()),
cx,
Some(did),
Expand Down
Loading