Skip to content

Commit 63fadee

Browse files
committed
mir: add debug assertion to check polymorphization
This commit adds some debug assertions to `ensure_monomorphic_enough` which checks that unused generic parameters have been replaced with a parameter. Signed-off-by: David Wood <[email protected]>
1 parent 70b49c7 commit 63fadee

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/librustc_mir/interpret/util.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,26 @@ where
4747
unused_params.contains(index).map(|unused| !unused).unwrap_or(true);
4848
// Only recurse when generic parameters in fns, closures and generators
4949
// are used and require substitution.
50-
if is_used && subst.needs_subst() {
50+
match (is_used, subst.needs_subst()) {
5151
// Just in case there are closures or generators within this subst,
5252
// recurse.
53-
if subst.super_visit_with(self) {
53+
(true, true) if subst.super_visit_with(self) => {
5454
// Only return when we find a parameter so the remaining substs
5555
// are not skipped.
5656
return true;
5757
}
58+
// Confirm that polymorphization replaced the parameter with
59+
// `ty::Param`/`ty::ConstKind::Param`.
60+
(false, true) if cfg!(debug_assertions) => match subst.unpack() {
61+
ty::subst::GenericArgKind::Type(ty) => {
62+
assert!(matches!(ty.kind, ty::Param(_)))
63+
}
64+
ty::subst::GenericArgKind::Const(ct) => {
65+
assert!(matches!(ct.val, ty::ConstKind::Param(_)))
66+
}
67+
ty::subst::GenericArgKind::Lifetime(..) => (),
68+
},
69+
_ => {}
5870
}
5971
}
6072
false

0 commit comments

Comments
 (0)