Add trait_object_dummy_self to CommonTypes
This commit is contained in:
parent
dd7483c750
commit
51a792d01b
2 changed files with 15 additions and 12 deletions
|
@ -219,6 +219,11 @@ pub struct CommonTypes<'tcx> {
|
|||
pub never: Ty<'tcx>,
|
||||
pub err: Ty<'tcx>,
|
||||
|
||||
/// Dummy type used for the `Self` of a `TraitRef` created for converting
|
||||
/// a trait object, and which gets removed in `ExistentialTraitRef`.
|
||||
/// This type must not appear anywhere in other converted types.
|
||||
pub trait_object_dummy_self: Ty<'tcx>,
|
||||
|
||||
pub re_empty: Region<'tcx>,
|
||||
pub re_static: Region<'tcx>,
|
||||
pub re_erased: Region<'tcx>,
|
||||
|
@ -955,6 +960,8 @@ impl<'tcx> CommonTypes<'tcx> {
|
|||
f32: mk(Float(ast::FloatTy::F32)),
|
||||
f64: mk(Float(ast::FloatTy::F64)),
|
||||
|
||||
trait_object_dummy_self: mk(Infer(ty::FreshTy(0))),
|
||||
|
||||
re_empty: mk_region(RegionKind::ReEmpty),
|
||||
re_static: mk_region(RegionKind::ReStatic),
|
||||
re_erased: mk_region(RegionKind::ReErased),
|
||||
|
|
|
@ -99,12 +99,6 @@ enum GenericArgPosition {
|
|||
MethodCall,
|
||||
}
|
||||
|
||||
/// Dummy type used for the `Self` of a `TraitRef` created for converting
|
||||
/// a trait object, and which gets removed in `ExistentialTraitRef`.
|
||||
/// This type must not appear anywhere in other converted types.
|
||||
#[cfg_attr(not(stage0), allow(usage_of_ty_tykind))]
|
||||
const TRAIT_OBJECT_DUMMY_SELF: ty::TyKind<'static> = ty::Infer(ty::FreshTy(0));
|
||||
|
||||
impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
||||
pub fn ast_region_to_region(&self,
|
||||
lifetime: &hir::Lifetime,
|
||||
|
@ -596,7 +590,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
infer_types,
|
||||
);
|
||||
|
||||
let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
|
||||
let is_object = self_ty.map_or(false, |ty| {
|
||||
ty.sty == self.tcx().types.trait_object_dummy_self.sty
|
||||
});
|
||||
let default_needs_object_self = |param: &ty::GenericParamDef| {
|
||||
if let GenericParamDefKind::Type { has_default, .. } = param.kind {
|
||||
if is_object && has_default {
|
||||
|
@ -957,10 +953,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
}
|
||||
|
||||
/// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
|
||||
/// removing the dummy `Self` type (`TRAIT_OBJECT_DUMMY_SELF`).
|
||||
/// 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().sty != TRAIT_OBJECT_DUMMY_SELF {
|
||||
if trait_ref.self_ty().sty != self.tcx().types.trait_object_dummy_self.sty {
|
||||
bug!("trait_ref_to_existential called on {:?} with non-dummy Self", trait_ref);
|
||||
}
|
||||
ty::ExistentialTraitRef::erase_self_ty(self.tcx(), trait_ref)
|
||||
|
@ -981,7 +977,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
}
|
||||
|
||||
let mut projection_bounds = Vec::new();
|
||||
let dummy_self = tcx.mk_ty(TRAIT_OBJECT_DUMMY_SELF);
|
||||
let dummy_self = self.tcx().types.trait_object_dummy_self;
|
||||
let (principal, potential_assoc_types) = self.instantiate_poly_trait_ref(
|
||||
&trait_bounds[0],
|
||||
dummy_self,
|
||||
|
@ -1031,7 +1027,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
}
|
||||
ty::Predicate::Projection(pred) => {
|
||||
// A `Self` within the original bound will be substituted with a
|
||||
// `TRAIT_OBJECT_DUMMY_SELF`, so check for that.
|
||||
// `trait_object_dummy_self`, so check for that.
|
||||
let references_self =
|
||||
pred.skip_binder().ty.walk().any(|t| t == dummy_self);
|
||||
|
||||
|
@ -1131,7 +1127,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
err.emit();
|
||||
}
|
||||
|
||||
// Erase the `dummy_self` (`TRAIT_OBJECT_DUMMY_SELF`) used above.
|
||||
// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
|
||||
let existential_principal = principal.map_bound(|trait_ref| {
|
||||
self.trait_ref_to_existential(trait_ref)
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue