diff options
| author | Lukas Markeffsky <@> | 2025-02-10 22:06:19 +0000 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2025-02-13 08:52:47 -0800 |
| commit | a061e7eb65161af1a994257f0619d0ee7da24306 (patch) | |
| tree | cf36e8fbf779648ffb0221f8ad641503eb65ee11 | |
| parent | 4991b29a369a7f01709948359908ed097e1ad618 (diff) | |
| download | rust-a061e7eb65161af1a994257f0619d0ee7da24306.tar.gz rust-a061e7eb65161af1a994257f0619d0ee7da24306.zip | |
fix ensure_monomorphic_enough
(cherry picked from commit c1da4f1d3c4fc4beb5edcfa8a303a1dcbe27b65e)
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/util.rs | 44 | ||||
| -rw-r--r-- | tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff | 3 | ||||
| -rw-r--r-- | tests/mir-opt/gvn_type_id_polymorphic.rs | 2 |
3 files changed, 5 insertions, 44 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index ecb7c3fc93c..8fd0b93454d 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -1,12 +1,8 @@ -use std::ops::ControlFlow; - use rustc_hir::def_id::LocalDefId; use rustc_middle::mir; use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer}; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::{ - self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, -}; +use rustc_middle::ty::{TyCtxt, TypeVisitable, TypeVisitableExt}; use tracing::debug; use super::{InterpCx, MPlaceTy, MemoryKind, interp_ok, throw_inval}; @@ -20,44 +16,10 @@ where T: TypeVisitable<TyCtxt<'tcx>>, { debug!("ensure_monomorphic_enough: ty={:?}", ty); - if !ty.has_param() { - return interp_ok(()); - } - - struct FoundParam; - struct UsedParamsNeedInstantiationVisitor {} - - impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor { - type Result = ControlFlow<FoundParam>; - - fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { - if !ty.has_param() { - return ControlFlow::Continue(()); - } - - match *ty.kind() { - ty::Param(_) => ControlFlow::Break(FoundParam), - ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) | ty::FnDef(..) => { - ControlFlow::Continue(()) - } - _ => ty.super_visit_with(self), - } - } - - fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result { - match c.kind() { - ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam), - _ => c.super_visit_with(self), - } - } - } - - let mut vis = UsedParamsNeedInstantiationVisitor {}; - if matches!(ty.visit_with(&mut vis), ControlFlow::Break(FoundParam)) { + if ty.has_param() { throw_inval!(TooGeneric); - } else { - interp_ok(()) } + interp_ok(()) } impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> { diff --git a/tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff b/tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff index c9d641472d0..2f83f54d2af 100644 --- a/tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff +++ b/tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff @@ -5,8 +5,7 @@ let mut _0: bool; bb0: { -- _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1}); -+ _0 = const false; + _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1}); return; } } diff --git a/tests/mir-opt/gvn_type_id_polymorphic.rs b/tests/mir-opt/gvn_type_id_polymorphic.rs index a5b936e52da..39bc5c24ecc 100644 --- a/tests/mir-opt/gvn_type_id_polymorphic.rs +++ b/tests/mir-opt/gvn_type_id_polymorphic.rs @@ -12,7 +12,7 @@ const fn type_id_of_val<T: 'static>(_: &T) -> u128 { // EMIT_MIR gvn_type_id_polymorphic.cursed_is_i32.GVN.diff fn cursed_is_i32<T: 'static>() -> bool { // CHECK-LABEL: fn cursed_is_i32( - // CHECK: _0 = const false; + // CHECK: _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1}); // CHECK-NEXT: return; (const { type_id_of_val(&generic::<T>) } == const { type_id_of_val(&generic::<i32>) }) } |
