@@ -82,6 +82,10 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
8282 return Err ( ValTreeCreationError :: NodesOverflow ) ;
8383 }
8484
85+ if ty:: maybe_not_supported_generic_const_param ( ty) . is_some_and ( |v| v) {
86+ return Err ( ValTreeCreationError :: NonSupportedType ) ;
87+ }
88+
8589 match ty. kind ( ) {
8690 ty:: FnDef ( ..) => {
8791 * num_nodes += 1 ;
@@ -97,62 +101,38 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
97101 Ok ( ty:: ValTree :: Leaf ( val. assert_int ( ) ) )
98102 }
99103
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 {
108106 return Err ( ValTreeCreationError :: Other ) ;
109107 } ;
110108 debug ! ( ?derefd_place) ;
111109
112110 const_to_valtree_inner ( ecx, & derefd_place, num_nodes)
113111 }
114112
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) ,
127116
128117 ty:: Adt ( def, _) => {
129118 if def. is_union ( ) {
130- return Err ( ValTreeCreationError :: NonSupportedType ) ;
119+ unreachable ! ( ) ;
131120 } else if def. variants ( ) . is_empty ( ) {
132121 bug ! ( "uninhabited types should have errored and never gotten converted to valtree" )
133122 }
134123
135124 let Ok ( variant) = ecx. read_discriminant ( place) else {
136125 return Err ( ValTreeCreationError :: Other ) ;
137126 } ;
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+ )
139134 }
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 ! ( ) ,
156136 }
157137}
158138
0 commit comments