Skip to content

Commit 36a91ab

Browse files
Assert that closures and generators are made with the right number of substitutions
1 parent 789dd0b commit 36a91ab

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

compiler/rustc_middle/src/ty/context.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1872,18 +1872,28 @@ impl<'tcx> TyCtxt<'tcx> {
18721872
}
18731873

18741874
#[inline]
1875-
pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> {
1876-
self.mk_ty_from_kind(Closure(closure_id, closure_substs))
1875+
pub fn mk_closure(self, def_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> {
1876+
debug_assert_eq!(
1877+
closure_substs.len(),
1878+
self.generics_of(self.typeck_root_def_id(def_id)).count() + 3,
1879+
"closure constructed with incorrect substitutions"
1880+
);
1881+
self.mk_ty_from_kind(Closure(def_id, closure_substs))
18771882
}
18781883

18791884
#[inline]
18801885
pub fn mk_generator(
18811886
self,
1882-
id: DefId,
1887+
def_id: DefId,
18831888
generator_substs: SubstsRef<'tcx>,
18841889
movability: hir::Movability,
18851890
) -> Ty<'tcx> {
1886-
self.mk_ty_from_kind(Generator(id, generator_substs, movability))
1891+
debug_assert_eq!(
1892+
generator_substs.len(),
1893+
self.generics_of(self.typeck_root_def_id(def_id)).count() + 5,
1894+
"generator constructed with incorrect number of substitutions"
1895+
);
1896+
self.mk_ty_from_kind(Generator(def_id, generator_substs, movability))
18871897
}
18881898

18891899
#[inline]

0 commit comments

Comments
 (0)