Rollup merge of #100057 - GuillaumeGomez:rm-more-clean-impl, r=Dylan-DPC
Remove more Clean trait implementations Follow-up of https://github.com/rust-lang/rust/pull/99638. r? ``@notriddle``
This commit is contained in:
commit
269d15fbf8
@ -120,7 +120,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
|||||||
kind: Box::new(ImplItem(Box::new(Impl {
|
kind: Box::new(ImplItem(Box::new(Impl {
|
||||||
unsafety: hir::Unsafety::Normal,
|
unsafety: hir::Unsafety::Normal,
|
||||||
generics: new_generics,
|
generics: new_generics,
|
||||||
trait_: Some(trait_ref.clean(self.cx)),
|
trait_: Some(clean_trait_ref_with_bindings(self.cx, trait_ref, &[])),
|
||||||
for_: clean_middle_ty(ty, self.cx, None),
|
for_: clean_middle_ty(ty, self.cx, None),
|
||||||
items: Vec::new(),
|
items: Vec::new(),
|
||||||
polarity,
|
polarity,
|
||||||
|
@ -115,7 +115,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
|||||||
),
|
),
|
||||||
// FIXME(eddyb) compute both `trait_` and `for_` from
|
// FIXME(eddyb) compute both `trait_` and `for_` from
|
||||||
// the post-inference `trait_ref`, as it's more accurate.
|
// the post-inference `trait_ref`, as it's more accurate.
|
||||||
trait_: Some(trait_ref.0.clean(cx)),
|
trait_: Some(clean_trait_ref_with_bindings(cx, trait_ref.0, &[])),
|
||||||
for_: clean_middle_ty(ty.0, cx, None),
|
for_: clean_middle_ty(ty.0, cx, None),
|
||||||
items: cx.tcx
|
items: cx.tcx
|
||||||
.associated_items(impl_def_id)
|
.associated_items(impl_def_id)
|
||||||
|
@ -16,9 +16,9 @@ use rustc_span::hygiene::MacroKind;
|
|||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
|
|
||||||
use crate::clean::{
|
use crate::clean::{
|
||||||
self, clean_fn_decl_from_did_and_sig, clean_middle_field, clean_middle_ty, clean_ty,
|
self, clean_fn_decl_from_did_and_sig, clean_middle_field, clean_middle_ty,
|
||||||
clean_ty_generics, clean_variant_def, clean_visibility, utils, Attributes, AttributesExt,
|
clean_trait_ref_with_bindings, clean_ty, clean_ty_generics, clean_variant_def,
|
||||||
Clean, ImplKind, ItemId, Type, Visibility,
|
clean_visibility, utils, Attributes, AttributesExt, Clean, ImplKind, ItemId, Type, Visibility,
|
||||||
};
|
};
|
||||||
use crate::core::DocContext;
|
use crate::core::DocContext;
|
||||||
use crate::formats::item_type::ItemType;
|
use crate::formats::item_type::ItemType;
|
||||||
@ -450,7 +450,7 @@ pub(crate) fn build_impl(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
let polarity = tcx.impl_polarity(did);
|
let polarity = tcx.impl_polarity(did);
|
||||||
let trait_ = associated_trait.map(|t| t.clean(cx));
|
let trait_ = associated_trait.map(|t| clean_trait_ref_with_bindings(cx, t, &[]));
|
||||||
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
|
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
|
||||||
super::build_deref_target_impls(cx, &trait_items, ret);
|
super::build_deref_target_impls(cx, &trait_items, ret);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
|
|||||||
impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
|
impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
|
||||||
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
|
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
|
||||||
Some(match *self {
|
Some(match *self {
|
||||||
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)),
|
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(clean_lifetime(lt, cx)),
|
||||||
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
|
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
|
||||||
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
|
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean_trait_ref_with_bindings<'tcx>(
|
pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
|
||||||
cx: &mut DocContext<'tcx>,
|
cx: &mut DocContext<'tcx>,
|
||||||
trait_ref: ty::TraitRef<'tcx>,
|
trait_ref: ty::TraitRef<'tcx>,
|
||||||
bindings: &[TypeBinding],
|
bindings: &[TypeBinding],
|
||||||
@ -174,12 +174,6 @@ fn clean_trait_ref_with_bindings<'tcx>(
|
|||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Clean<'tcx, Path> for ty::TraitRef<'tcx> {
|
|
||||||
fn clean(&self, cx: &mut DocContext<'tcx>) -> Path {
|
|
||||||
clean_trait_ref_with_bindings(cx, *self, &[])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clean_poly_trait_ref_with_bindings<'tcx>(
|
fn clean_poly_trait_ref_with_bindings<'tcx>(
|
||||||
cx: &mut DocContext<'tcx>,
|
cx: &mut DocContext<'tcx>,
|
||||||
poly_trait_ref: ty::PolyTraitRef<'tcx>,
|
poly_trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
@ -214,21 +208,19 @@ impl<'tcx> Clean<'tcx, GenericBound> for ty::PolyTraitRef<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Clean<'tcx, Lifetime> for hir::Lifetime {
|
fn clean_lifetime<'tcx>(lifetime: hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime {
|
||||||
fn clean(&self, cx: &mut DocContext<'tcx>) -> Lifetime {
|
let def = cx.tcx.named_region(lifetime.hir_id);
|
||||||
let def = cx.tcx.named_region(self.hir_id);
|
if let Some(
|
||||||
if let Some(
|
rl::Region::EarlyBound(_, node_id)
|
||||||
rl::Region::EarlyBound(_, node_id)
|
| rl::Region::LateBound(_, _, node_id)
|
||||||
| rl::Region::LateBound(_, _, node_id)
|
| rl::Region::Free(_, node_id),
|
||||||
| rl::Region::Free(_, node_id),
|
) = def
|
||||||
) = def
|
{
|
||||||
{
|
if let Some(lt) = cx.substs.get(&node_id).and_then(|p| p.as_lt()).cloned() {
|
||||||
if let Some(lt) = cx.substs.get(&node_id).and_then(|p| p.as_lt()).cloned() {
|
return lt;
|
||||||
return lt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Lifetime(self.name.ident().name)
|
|
||||||
}
|
}
|
||||||
|
Lifetime(lifetime.name.ident().name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
|
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
|
||||||
@ -305,7 +297,7 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
|
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
|
||||||
lifetime: wrp.lifetime.clean(cx),
|
lifetime: clean_lifetime(wrp.lifetime, cx),
|
||||||
bounds: wrp.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
|
bounds: wrp.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -426,7 +418,7 @@ fn clean_projection<'tcx>(
|
|||||||
def_id: Option<DefId>,
|
def_id: Option<DefId>,
|
||||||
) -> Type {
|
) -> Type {
|
||||||
let lifted = ty.lift_to_tcx(cx.tcx).unwrap();
|
let lifted = ty.lift_to_tcx(cx.tcx).unwrap();
|
||||||
let trait_ = lifted.trait_ref(cx.tcx).clean(cx);
|
let trait_ = clean_trait_ref_with_bindings(cx, lifted.trait_ref(cx.tcx), &[]);
|
||||||
let self_type = clean_middle_ty(ty.self_ty(), cx, None);
|
let self_type = clean_middle_ty(ty.self_ty(), cx, None);
|
||||||
let self_def_id = if let Some(def_id) = def_id {
|
let self_def_id = if let Some(def_id) = def_id {
|
||||||
cx.tcx.opt_parent(def_id).or(Some(def_id))
|
cx.tcx.opt_parent(def_id).or(Some(def_id))
|
||||||
@ -518,7 +510,7 @@ fn clean_generic_param<'tcx>(
|
|||||||
.filter(|bp| !bp.in_where_clause)
|
.filter(|bp| !bp.in_where_clause)
|
||||||
.flat_map(|bp| bp.bounds)
|
.flat_map(|bp| bp.bounds)
|
||||||
.map(|bound| match bound {
|
.map(|bound| match bound {
|
||||||
hir::GenericBound::Outlives(lt) => lt.clean(cx),
|
hir::GenericBound::Outlives(lt) => clean_lifetime(*lt, cx),
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@ -1425,7 +1417,8 @@ fn maybe_expand_private_type_alias<'tcx>(
|
|||||||
});
|
});
|
||||||
if let Some(lt) = lifetime.cloned() {
|
if let Some(lt) = lifetime.cloned() {
|
||||||
let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
|
let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
|
||||||
let cleaned = if !lt.is_elided() { lt.clean(cx) } else { Lifetime::elided() };
|
let cleaned =
|
||||||
|
if !lt.is_elided() { clean_lifetime(lt, cx) } else { Lifetime::elided() };
|
||||||
substs.insert(lt_def_id.to_def_id(), SubstParam::Lifetime(cleaned));
|
substs.insert(lt_def_id.to_def_id(), SubstParam::Lifetime(cleaned));
|
||||||
}
|
}
|
||||||
indices.lifetimes += 1;
|
indices.lifetimes += 1;
|
||||||
@ -1497,7 +1490,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||||||
// there's no case where it could cause the function to fail to compile.
|
// there's no case where it could cause the function to fail to compile.
|
||||||
let elided =
|
let elided =
|
||||||
l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh));
|
l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh));
|
||||||
let lifetime = if elided { None } else { Some(l.clean(cx)) };
|
let lifetime = if elided { None } else { Some(clean_lifetime(*l, cx)) };
|
||||||
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
|
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
|
||||||
}
|
}
|
||||||
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
||||||
@ -1533,7 +1526,8 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||||||
TyKind::Path(_) => clean_qpath(ty, cx),
|
TyKind::Path(_) => clean_qpath(ty, cx),
|
||||||
TyKind::TraitObject(bounds, ref lifetime, _) => {
|
TyKind::TraitObject(bounds, ref lifetime, _) => {
|
||||||
let bounds = bounds.iter().map(|bound| bound.clean(cx)).collect();
|
let bounds = bounds.iter().map(|bound| bound.clean(cx)).collect();
|
||||||
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
|
let lifetime =
|
||||||
|
if !lifetime.is_elided() { Some(clean_lifetime(*lifetime, cx)) } else { None };
|
||||||
DynTrait(bounds, lifetime)
|
DynTrait(bounds, lifetime)
|
||||||
}
|
}
|
||||||
TyKind::BareFn(barefn) => BareFunction(Box::new(barefn.clean(cx))),
|
TyKind::BareFn(barefn) => BareFunction(Box::new(barefn.clean(cx))),
|
||||||
@ -1869,7 +1863,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|arg| match arg {
|
.map(|arg| match arg {
|
||||||
hir::GenericArg::Lifetime(lt) if !lt.is_elided() => {
|
hir::GenericArg::Lifetime(lt) if !lt.is_elided() => {
|
||||||
GenericArg::Lifetime(lt.clean(cx))
|
GenericArg::Lifetime(clean_lifetime(*lt, cx))
|
||||||
}
|
}
|
||||||
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
|
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
|
||||||
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
|
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user