Assert that various types have the right amount of generic args and fix the sites that used the wrong amount
This commit is contained in:
parent
d9a02b0fb7
commit
6f77c97b38
27 changed files with 153 additions and 144 deletions
|
@ -2532,6 +2532,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn mk_fn_def(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||
debug_assert_eq!(
|
||||
self.generics_of(def_id).count(),
|
||||
substs.len(),
|
||||
"wrong number of generic parameters for {def_id:?}: {substs:?}",
|
||||
);
|
||||
self.mk_ty(FnDef(def_id, substs))
|
||||
}
|
||||
|
||||
|
@ -2552,6 +2557,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn mk_projection(self, item_def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||
debug_assert_eq!(
|
||||
self.generics_of(item_def_id).count(),
|
||||
substs.len(),
|
||||
"wrong number of generic parameters for {item_def_id:?}: {substs:?}",
|
||||
);
|
||||
self.mk_ty(Projection(ProjectionTy { item_def_id, substs }))
|
||||
}
|
||||
|
||||
|
@ -2803,6 +2813,21 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
|
||||
}
|
||||
|
||||
pub fn mk_trait_ref(
|
||||
self,
|
||||
trait_def_id: DefId,
|
||||
self_ty: Ty<'tcx>,
|
||||
rest: &[GenericArg<'tcx>],
|
||||
) -> ty::TraitRef<'tcx> {
|
||||
debug_assert_eq!(
|
||||
self.generics_of(trait_def_id).count() - 1,
|
||||
rest.len(),
|
||||
"wrong number of generic parameters for {trait_def_id:?} on self type {self_ty:?}: {rest:?} \nDid you accidentally include the self-type in the params list?"
|
||||
);
|
||||
let substs = self.mk_substs_trait(self_ty, rest);
|
||||
ty::TraitRef::new(trait_def_id, substs)
|
||||
}
|
||||
|
||||
pub fn mk_bound_variable_kinds<
|
||||
I: InternAs<[ty::BoundVariableKind], &'tcx List<ty::BoundVariableKind>>,
|
||||
>(
|
||||
|
|
|
@ -719,10 +719,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
|
|||
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
|
||||
}
|
||||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let trait_ref = self.rebind(ty::TraitRef {
|
||||
def_id: did,
|
||||
substs: tcx.mk_substs_trait(self_ty, &[]),
|
||||
});
|
||||
let trait_ref = self.rebind(tcx.mk_trait_ref(did, self_ty, &[]));
|
||||
trait_ref.without_const().to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
@ -909,7 +906,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
|
|||
// otherwise the escaping vars would be captured by the binder
|
||||
// debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||
|
||||
ty::TraitRef { def_id: self.def_id, substs: tcx.mk_substs_trait(self_ty, self.substs) }
|
||||
tcx.mk_trait_ref(self.def_id, self_ty, self.substs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue