Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug-assert that closures and generators are made with the right number of substitutions #112189

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down