Skip to content

Commit c1da4f1

Browse files
author
Lukas Markeffsky
committed
fix ensure_monomorphic_enough
1 parent 4898753 commit c1da4f1

File tree

3 files changed

+5
-44
lines changed

3 files changed

+5
-44
lines changed

Diff for: compiler/rustc_const_eval/src/interpret/util.rs

+3-41
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use std::ops::ControlFlow;
2-
31
use rustc_hir::def_id::LocalDefId;
42
use rustc_middle::mir;
53
use rustc_middle::mir::interpret::{AllocInit, Allocation, InterpResult, Pointer};
64
use 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};
106
use tracing::debug;
117

128
use 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

6325
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {

Diff for: tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
let mut _0: bool;
66

77
bb0: {
8-
- _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1});
9-
+ _0 = const false;
8+
_0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1});
109
return;
1110
}
1211
}

Diff for: tests/mir-opt/gvn_type_id_polymorphic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const fn type_id_of_val<T: 'static>(_: &T) -> u128 {
1212
// EMIT_MIR gvn_type_id_polymorphic.cursed_is_i32.GVN.diff
1313
fn cursed_is_i32<T: 'static>() -> bool {
1414
// CHECK-LABEL: fn cursed_is_i32(
15-
// CHECK: _0 = const false;
15+
// CHECK: _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1});
1616
// CHECK-NEXT: return;
1717
(const { type_id_of_val(&generic::<T>) } == const { type_id_of_val(&generic::<i32>) })
1818
}

0 commit comments

Comments
 (0)