Skip to content

Commit

Permalink
mir: add debug assertion to check polymorphization
Browse files Browse the repository at this point in the history
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 <david@davidtw.co>
  • Loading branch information
davidtwco committed Aug 4, 2020
1 parent 70b49c7 commit 63fadee
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/librustc_mir/interpret/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ where
unused_params.contains(index).map(|unused| !unused).unwrap_or(true);
// Only recurse when generic parameters in fns, closures and generators
// are used and require substitution.
if is_used && subst.needs_subst() {
match (is_used, subst.needs_subst()) {
// Just in case there are closures or generators within this subst,
// recurse.
if subst.super_visit_with(self) {
(true, true) if subst.super_visit_with(self) => {
// Only return when we find a parameter so the remaining substs
// are not skipped.
return true;
}
// Confirm that polymorphization replaced the parameter with
// `ty::Param`/`ty::ConstKind::Param`.
(false, true) if cfg!(debug_assertions) => match subst.unpack() {
ty::subst::GenericArgKind::Type(ty) => {
assert!(matches!(ty.kind, ty::Param(_)))
}
ty::subst::GenericArgKind::Const(ct) => {
assert!(matches!(ct.val, ty::ConstKind::Param(_)))
}
ty::subst::GenericArgKind::Lifetime(..) => (),
},
_ => {}
}
}
false
Expand Down

0 comments on commit 63fadee

Please sign in to comment.