]> git.lizzy.rs Git - rust.git/commitdiff
Don't assert polymorphization has taken effect in const eval
authorWesley Wiser <wesleywiser@microsoft.com>
Fri, 1 Oct 2021 01:58:49 +0000 (21:58 -0400)
committerCamille GILLOT <gillot.camille@gmail.com>
Thu, 30 Jun 2022 19:45:29 +0000 (21:45 +0200)
Const eval no longer runs MIR optimizations so unless this is getting
run as part of a MIR optimization like const-prop, there can be unused
type parameters even if polymorphization is enabled.

compiler/rustc_const_eval/src/interpret/util.rs

index b9866995e9f95a9f9a3e1e67574c8968e3749f95..9d7905ed9a8398e2a027c11eafbe55bc5113a59c 100644 (file)
@@ -44,22 +44,10 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
                         let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
                         // Only recurse when generic parameters in fns, closures and generators
                         // are used and require substitution.
                         let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
                         // Only recurse when generic parameters in fns, closures and generators
                         // are used and require substitution.
-                        match (is_used, subst.needs_subst()) {
-                            // Just in case there are closures or generators within this subst,
-                            // recurse.
-                            (true, true) => return subst.visit_with(self),
-                            // 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.kind(), ty::ConstKind::Param(_)))
-                                }
-                                ty::subst::GenericArgKind::Lifetime(..) => (),
-                            },
-                            _ => {}
+                        // Just in case there are closures or generators within this subst,
+                        // recurse.
+                        if is_used && subst.needs_subst() {
+                            return subst.visit_with(self);
                         }
                     }
                     ControlFlow::CONTINUE
                         }
                     }
                     ControlFlow::CONTINUE