Move trait_ref_to_existential
to a closure
review comment
This commit is contained in:
parent
8d1c2612f8
commit
0ff73535ed
1 changed files with 19 additions and 21 deletions
|
@ -1224,25 +1224,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
)
|
||||
}
|
||||
|
||||
/// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
|
||||
/// removing the dummy `Self` type (`trait_object_dummy_self`).
|
||||
fn trait_ref_to_existential(
|
||||
&self,
|
||||
trait_ref: ty::TraitRef<'tcx>,
|
||||
) -> ty::ExistentialTraitRef<'tcx> {
|
||||
if trait_ref.self_ty() != self.tcx().types.trait_object_dummy_self {
|
||||
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`, which
|
||||
// picks up non-supertraits where clauses - but also, the object safety completely
|
||||
// ignores trait aliases, which could be object safety hazards. We `delay_span_bug`
|
||||
// here to avoid an ICE in stable even when the feature is disabled. (#66420)
|
||||
self.tcx().sess.delay_span_bug(DUMMY_SP, &format!(
|
||||
"trait_ref_to_existential called on {:?} with non-dummy Self",
|
||||
trait_ref,
|
||||
));
|
||||
}
|
||||
ty::ExistentialTraitRef::erase_self_ty(self.tcx(), trait_ref)
|
||||
}
|
||||
|
||||
fn conv_object_ty_poly_trait_ref(&self,
|
||||
span: Span,
|
||||
trait_bounds: &[hir::PolyTraitRef],
|
||||
|
@ -1424,13 +1405,30 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
debug!("regular_traits: {:?}", regular_traits);
|
||||
debug!("auto_traits: {:?}", auto_traits);
|
||||
|
||||
// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
|
||||
// removing the dummy `Self` type (`trait_object_dummy_self`).
|
||||
let trait_ref_to_existential = |trait_ref: ty::TraitRef<'tcx>| {
|
||||
if trait_ref.self_ty() != dummy_self {
|
||||
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`,
|
||||
// which picks up non-supertraits where clauses - but also, the object safety
|
||||
// completely ignores trait aliases, which could be object safety hazards. We
|
||||
// `delay_span_bug` here to avoid an ICE in stable even when the feature is
|
||||
// disabled. (#66420)
|
||||
tcx.sess.delay_span_bug(DUMMY_SP, &format!(
|
||||
"trait_ref_to_existential called on {:?} with non-dummy Self",
|
||||
trait_ref,
|
||||
));
|
||||
}
|
||||
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
|
||||
};
|
||||
|
||||
// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
|
||||
let existential_trait_refs = regular_traits.iter().map(|i| {
|
||||
i.trait_ref().map_bound(|trait_ref| self.trait_ref_to_existential(trait_ref))
|
||||
i.trait_ref().map_bound(|trait_ref| trait_ref_to_existential(trait_ref))
|
||||
});
|
||||
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
|
||||
bound.map_bound(|b| {
|
||||
let trait_ref = self.trait_ref_to_existential(b.projection_ty.trait_ref(tcx));
|
||||
let trait_ref = trait_ref_to_existential(b.projection_ty.trait_ref(tcx));
|
||||
ty::ExistentialProjection {
|
||||
ty: b.ty,
|
||||
item_def_id: b.projection_ty.item_def_id,
|
||||
|
|
Loading…
Add table
Reference in a new issue