Add GenericParamDef::to_error and InternalSubsts::extend_with_error
This commit is contained in:
parent
19175e9b75
commit
6dc2aa2675
3 changed files with 32 additions and 13 deletions
|
@ -101,6 +101,20 @@ impl GenericParamDef {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_error<'tcx>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
preceding_substs: &[ty::GenericArg<'tcx>],
|
||||
) -> ty::GenericArg<'tcx> {
|
||||
match &self.kind {
|
||||
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
|
||||
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
|
||||
ty::GenericParamDefKind::Const { .. } => {
|
||||
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -728,19 +728,8 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
|
|||
} else {
|
||||
// If this is an ill-formed auto trait, then synthesize
|
||||
// new error substs for the missing generics.
|
||||
let err_substs = ty::InternalSubsts::for_item(tcx, did, |def, substs| {
|
||||
if def.index == 0 {
|
||||
self_ty.into()
|
||||
} else {
|
||||
match &def.kind {
|
||||
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
|
||||
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
|
||||
ty::GenericParamDefKind::Const { .. } => tcx
|
||||
.const_error(tcx.bound_type_of(def.def_id).subst(tcx, substs))
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
});
|
||||
let err_substs =
|
||||
ty::InternalSubsts::extend_with_error(tcx, did, &[self_ty.into()]);
|
||||
tcx.mk_trait_ref(did, err_substs)
|
||||
};
|
||||
self.rebind(trait_ref).without_const().to_predicate(tcx)
|
||||
|
|
|
@ -352,6 +352,22 @@ impl<'tcx> InternalSubsts<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
// Extend an `original_substs` list to the full number of substs expected by `def_id`,
|
||||
// filling in the missing parameters with error ty/ct or 'static regions.
|
||||
pub fn extend_with_error(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
original_substs: &[GenericArg<'tcx>],
|
||||
) -> SubstsRef<'tcx> {
|
||||
ty::InternalSubsts::for_item(tcx, def_id, |def, substs| {
|
||||
if let Some(subst) = original_substs.get(def.index as usize) {
|
||||
*subst
|
||||
} else {
|
||||
def.to_error(tcx, substs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx {
|
||||
self.iter()
|
||||
|
|
Loading…
Add table
Reference in a new issue