1- use std::ops::ControlFlow;
2-
31use rustc_hir::def_id::LocalDefId;
42use rustc_middle::mir;
53use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer};
64use rustc_middle::ty::layout::TyAndLayout;
7- use rustc_middle::ty::{
8- self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
9- };
5+ use rustc_middle::ty::{TyCtxt, TypeVisitable, TypeVisitableExt};
106use tracing::debug;
117
128use super::{InterpCx, MPlaceTy, MemoryKind, interp_ok, throw_inval};
@@ -20,44 +16,10 @@ where
2016 T: TypeVisitable<TyCtxt<'tcx>>,
2117{
2218 debug!("ensure_monomorphic_enough: ty={:?}", ty);
23- if !ty.has_param() {
24- return interp_ok(());
25- }
26-
27- struct FoundParam;
28- struct UsedParamsNeedInstantiationVisitor {}
29-
30- impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor {
31- type Result = ControlFlow<FoundParam>;
32-
33- fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
34- if !ty.has_param() {
35- return ControlFlow::Continue(());
36- }
37-
38- match *ty.kind() {
39- ty::Param(_) => ControlFlow::Break(FoundParam),
40- ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) | ty::FnDef(..) => {
41- ControlFlow::Continue(())
42- }
43- _ => ty.super_visit_with(self),
44- }
45- }
46-
47- fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
48- match c.kind() {
49- ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
50- _ => c.super_visit_with(self),
51- }
52- }
53- }
54-
55- let mut vis = UsedParamsNeedInstantiationVisitor {};
56- if matches!(ty.visit_with(&mut vis), ControlFlow::Break(FoundParam)) {
19+ if ty.has_param() {
5720 throw_inval!(TooGeneric);
58- } else {
59- interp_ok(())
6021 }
22+ interp_ok(())
6123}
6224
6325impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
0 commit comments