Skip to content

Commit 099b9da

Browse files
estebankMark-Simulacrum
authored andcommitted
Move trait_ref_to_existential to a closure
review comment
1 parent 2f44bb0 commit 099b9da

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,25 +1221,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12211221
)
12221222
}
12231223

1224-
/// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
1225-
/// removing the dummy `Self` type (`trait_object_dummy_self`).
1226-
fn trait_ref_to_existential(
1227-
&self,
1228-
trait_ref: ty::TraitRef<'tcx>,
1229-
) -> ty::ExistentialTraitRef<'tcx> {
1230-
if trait_ref.self_ty() != self.tcx().types.trait_object_dummy_self {
1231-
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`, which
1232-
// picks up non-supertraits where clauses - but also, the object safety completely
1233-
// ignores trait aliases, which could be object safety hazards. We `delay_span_bug`
1234-
// here to avoid an ICE in stable even when the feature is disabled. (#66420)
1235-
self.tcx().sess.delay_span_bug(DUMMY_SP, &format!(
1236-
"trait_ref_to_existential called on {:?} with non-dummy Self",
1237-
trait_ref,
1238-
));
1239-
}
1240-
ty::ExistentialTraitRef::erase_self_ty(self.tcx(), trait_ref)
1241-
}
1242-
12431224
fn conv_object_ty_poly_trait_ref(&self,
12441225
span: Span,
12451226
trait_bounds: &[hir::PolyTraitRef],
@@ -1421,13 +1402,30 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14211402
debug!("regular_traits: {:?}", regular_traits);
14221403
debug!("auto_traits: {:?}", auto_traits);
14231404

1405+
// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
1406+
// removing the dummy `Self` type (`trait_object_dummy_self`).
1407+
let trait_ref_to_existential = |trait_ref: ty::TraitRef<'tcx>| {
1408+
if trait_ref.self_ty() != dummy_self {
1409+
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`,
1410+
// which picks up non-supertraits where clauses - but also, the object safety
1411+
// completely ignores trait aliases, which could be object safety hazards. We
1412+
// `delay_span_bug` here to avoid an ICE in stable even when the feature is
1413+
// disabled. (#66420)
1414+
tcx.sess.delay_span_bug(DUMMY_SP, &format!(
1415+
"trait_ref_to_existential called on {:?} with non-dummy Self",
1416+
trait_ref,
1417+
));
1418+
}
1419+
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
1420+
};
1421+
14241422
// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
14251423
let existential_trait_refs = regular_traits.iter().map(|i| {
1426-
i.trait_ref().map_bound(|trait_ref| self.trait_ref_to_existential(trait_ref))
1424+
i.trait_ref().map_bound(|trait_ref| trait_ref_to_existential(trait_ref))
14271425
});
14281426
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
14291427
bound.map_bound(|b| {
1430-
let trait_ref = self.trait_ref_to_existential(b.projection_ty.trait_ref(tcx));
1428+
let trait_ref = trait_ref_to_existential(b.projection_ty.trait_ref(tcx));
14311429
ty::ExistentialProjection {
14321430
ty: b.ty,
14331431
item_def_id: b.projection_ty.item_def_id,

0 commit comments

Comments
 (0)