@@ -82,6 +82,10 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
82
82
return Err ( ValTreeCreationError :: NodesOverflow ) ;
83
83
}
84
84
85
+ if ty:: maybe_not_supported_generic_const_param ( ty) . is_some_and ( |v| v) {
86
+ return Err ( ValTreeCreationError :: NonSupportedType ) ;
87
+ }
88
+
85
89
match ty. kind ( ) {
86
90
ty:: FnDef ( ..) => {
87
91
* num_nodes += 1 ;
@@ -97,62 +101,38 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
97
101
Ok ( ty:: ValTree :: Leaf ( val. assert_int ( ) ) )
98
102
}
99
103
100
- // Raw pointers are not allowed in type level constants, as we cannot properly test them for
101
- // equality at compile-time (see `ptr_guaranteed_cmp`).
102
- // Technically we could allow function pointers (represented as `ty::Instance`), but this is not guaranteed to
103
- // agree with runtime equality tests.
104
- ty:: FnPtr ( _) | ty:: RawPtr ( _) => Err ( ValTreeCreationError :: NonSupportedType ) ,
105
-
106
- ty:: Ref ( _, _, _) => {
107
- let Ok ( derefd_place) = ecx. deref_pointer ( place) else {
104
+ ty:: Ref ( _, _, _) => {
105
+ let Ok ( derefd_place) = ecx. deref_pointer ( place) else {
108
106
return Err ( ValTreeCreationError :: Other ) ;
109
107
} ;
110
108
debug ! ( ?derefd_place) ;
111
109
112
110
const_to_valtree_inner ( ecx, & derefd_place, num_nodes)
113
111
}
114
112
115
- ty:: Str | ty:: Slice ( _) | ty:: Array ( _, _) => {
116
- slice_branches ( ecx, place, num_nodes)
117
- }
118
- // Trait objects are not allowed in type level constants, as we have no concept for
119
- // resolving their backing type, even if we can do that at const eval time. We may
120
- // hypothetically be able to allow `dyn StructuralEq` trait objects in the future,
121
- // but it is unclear if this is useful.
122
- ty:: Dynamic ( ..) => Err ( ValTreeCreationError :: NonSupportedType ) ,
123
-
124
- ty:: Tuple ( elem_tys) => {
125
- branches ( ecx, place, elem_tys. len ( ) , None , num_nodes)
126
- }
113
+ ty:: Str | ty:: Slice ( _) | ty:: Array ( _, _) => slice_branches ( ecx, place, num_nodes) ,
114
+
115
+ ty:: Tuple ( elem_tys) => branches ( ecx, place, elem_tys. len ( ) , None , num_nodes) ,
127
116
128
117
ty:: Adt ( def, _) => {
129
118
if def. is_union ( ) {
130
- return Err ( ValTreeCreationError :: NonSupportedType ) ;
119
+ unreachable ! ( ) ;
131
120
} else if def. variants ( ) . is_empty ( ) {
132
121
bug ! ( "uninhabited types should have errored and never gotten converted to valtree" )
133
122
}
134
123
135
124
let Ok ( variant) = ecx. read_discriminant ( place) else {
136
125
return Err ( ValTreeCreationError :: Other ) ;
137
126
} ;
138
- branches ( ecx, place, def. variant ( variant) . fields . len ( ) , def. is_enum ( ) . then_some ( variant) , num_nodes)
127
+ branches (
128
+ ecx,
129
+ place,
130
+ def. variant ( variant) . fields . len ( ) ,
131
+ def. is_enum ( ) . then_some ( variant) ,
132
+ num_nodes,
133
+ )
139
134
}
140
-
141
- ty:: Never
142
- | ty:: Error ( _)
143
- | ty:: Foreign ( ..)
144
- | ty:: Infer ( ty:: FreshIntTy ( _) )
145
- | ty:: Infer ( ty:: FreshFloatTy ( _) )
146
- // FIXME(oli-obk): we could look behind opaque types
147
- | ty:: Alias ( ..)
148
- | ty:: Param ( _)
149
- | ty:: Bound ( ..)
150
- | ty:: Placeholder ( ..)
151
- | ty:: Infer ( _)
152
- // FIXME(oli-obk): we can probably encode closures just like structs
153
- | ty:: Closure ( ..)
154
- | ty:: Coroutine ( ..)
155
- | ty:: CoroutineWitness ( ..) => Err ( ValTreeCreationError :: NonSupportedType ) ,
135
+ _ => unreachable ! ( ) ,
156
136
}
157
137
}
158
138
0 commit comments