summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-06-01 22:24:52 +0000
committerMichael Goulet <michael@errs.io>2023-06-01 22:37:20 +0000
commit36a91abba3c16a3c7cdff2c20f5391bf30dbf5e4 (patch)
tree0f1df6f4b56e45ad4cddee7460fe79978f1f46ec
parent789dd0b2a2cd68c129ba9b0aa1008939209adcfd (diff)
downloadrust-36a91abba3c16a3c7cdff2c20f5391bf30dbf5e4.tar.gz
rust-36a91abba3c16a3c7cdff2c20f5391bf30dbf5e4.zip
Assert that closures and generators are made with the right number of substitutions
-rw-r--r--compiler/rustc_middle/src/ty/context.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index b05e791211d..fac3d87fe1b 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1872,18 +1872,28 @@ impl<'tcx> TyCtxt<'tcx> {
     }
 
     #[inline]
-    pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> {
-        self.mk_ty_from_kind(Closure(closure_id, closure_substs))
+    pub fn mk_closure(self, def_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> {
+        debug_assert_eq!(
+            closure_substs.len(),
+            self.generics_of(self.typeck_root_def_id(def_id)).count() + 3,
+            "closure constructed with incorrect substitutions"
+        );
+        self.mk_ty_from_kind(Closure(def_id, closure_substs))
     }
 
     #[inline]
     pub fn mk_generator(
         self,
-        id: DefId,
+        def_id: DefId,
         generator_substs: SubstsRef<'tcx>,
         movability: hir::Movability,
     ) -> Ty<'tcx> {
-        self.mk_ty_from_kind(Generator(id, generator_substs, movability))
+        debug_assert_eq!(
+            generator_substs.len(),
+            self.generics_of(self.typeck_root_def_id(def_id)).count() + 5,
+            "generator constructed with incorrect number of substitutions"
+        );
+        self.mk_ty_from_kind(Generator(def_id, generator_substs, movability))
     }
 
     #[inline]