diff options
| author | David Wood <david@davidtw.co> | 2020-08-04 18:18:27 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2020-08-04 20:09:31 +0100 |
| commit | 63fadee21f4d3d7a07381dafc6cd2dfd644b5b02 (patch) | |
| tree | bfc9d9df16b2803404edb29e439d2fc6ea8c6061 /src | |
| parent | 70b49c7bddec33e6972610e024fcbb3576aa9be3 (diff) | |
| download | rust-63fadee21f4d3d7a07381dafc6cd2dfd644b5b02.tar.gz rust-63fadee21f4d3d7a07381dafc6cd2dfd644b5b02.zip | |
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 <david@davidtw.co>
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/interpret/util.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/librustc_mir/interpret/util.rs b/src/librustc_mir/interpret/util.rs index c0eac8a9305..57c5fc59cc0 100644 --- a/src/librustc_mir/interpret/util.rs +++ b/src/librustc_mir/interpret/util.rs @@ -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 |
