about summary refs log tree commit diff
path: root/compiler/rustc_monomorphize
diff options
context:
space:
mode:
authorb-naber <bn263@gmx.de>2022-07-04 20:07:14 +0200
committerb-naber <bn263@gmx.de>2022-09-13 17:44:52 +0200
commit372c4fd67fc41f0a06b1e6d804e8345db508761a (patch)
tree117fbc01e5d4a20ca4d22b5a5e75d11f93a32ddc /compiler/rustc_monomorphize
parent0726265442e7c3b0925286e831b24afe508e5cc8 (diff)
downloadrust-372c4fd67fc41f0a06b1e6d804e8345db508761a.tar.gz
rust-372c4fd67fc41f0a06b1e6d804e8345db508761a.zip
remove visit_const from mir visitors
Diffstat (limited to 'compiler/rustc_monomorphize')
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs37
-rw-r--r--compiler/rustc_monomorphize/src/polymorphize.rs13
2 files changed, 11 insertions, 39 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index 72fb566aff7..b7b24981217 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -795,42 +795,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
             }
         };
         collect_const_value(self.tcx, val, self.output);
-        self.visit_ty(literal.ty(), TyContext::Location(location));
-    }
-
-    #[instrument(skip(self), level = "debug")]
-    fn visit_const(&mut self, constant: ty::Const<'tcx>, location: Location) {
-        debug!("visiting const {:?} @ {:?}", constant, location);
-
-        let substituted_constant = self.monomorphize(constant);
-        let param_env = ty::ParamEnv::reveal_all();
-
-        match substituted_constant.kind() {
-            ty::ConstKind::Value(val) => {
-                let const_val = self.tcx.valtree_to_const_val((constant.ty(), val));
-                collect_const_value(self.tcx, const_val, self.output)
-            }
-            ty::ConstKind::Unevaluated(unevaluated) => {
-                match self.tcx.const_eval_resolve(param_env, unevaluated.expand(), None) {
-                    // The `monomorphize` call should have evaluated that constant already.
-                    Ok(val) => span_bug!(
-                        self.body.source_info(location).span,
-                        "collection encountered the unevaluated constant {} which evaluated to {:?}",
-                        substituted_constant,
-                        val
-                    ),
-                    Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => {}
-                    Err(ErrorHandled::TooGeneric) => span_bug!(
-                        self.body.source_info(location).span,
-                        "collection encountered polymorphic constant: {}",
-                        substituted_constant
-                    ),
-                }
-            }
-            _ => {}
-        }
-
-        self.super_const(constant);
+        MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
     }
 
     fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs
index b4bda57ba83..b5a8c6a2e72 100644
--- a/compiler/rustc_monomorphize/src/polymorphize.rs
+++ b/compiler/rustc_monomorphize/src/polymorphize.rs
@@ -9,7 +9,7 @@ use rustc_hir::{def::DefKind, def_id::DefId, ConstContext};
 use rustc_index::bit_set::FiniteBitSet;
 use rustc_middle::mir::{
     visit::{TyContext, Visitor},
-    ConstantKind, Local, LocalDecl, Location,
+    Constant, ConstantKind, Local, LocalDecl, Location,
 };
 use rustc_middle::ty::{
     self,
@@ -270,8 +270,15 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
         self.super_local_decl(local, local_decl);
     }
 
-    fn visit_const(&mut self, c: Const<'tcx>, _: Location) {
-        c.visit_with(self);
+    fn visit_constant(&mut self, ct: &Constant<'tcx>, location: Location) {
+        match ct.literal {
+            ConstantKind::Ty(c) => {
+                c.visit_with(self);
+            }
+            ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => {
+                Visitor::visit_ty(self, ty, TyContext::Location(location))
+            }
+        }
     }
 
     fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) {