1+ use rustc_data_structures:: stack:: ensure_sufficient_stack;
12use rustc_middle:: mir;
23use rustc_middle:: mir:: interpret:: { EvalToValTreeResult , GlobalId } ;
34use rustc_middle:: ty:: layout:: { LayoutCx , LayoutOf , TyAndLayout } ;
@@ -98,6 +99,16 @@ fn const_to_valtree_inner<'tcx>(
9899 Ok ( ty:: ValTree :: Leaf ( val. assert_int ( ) ) )
99100 }
100101
102+ ty:: Pat ( base, ..) => {
103+ let mut place = place. clone ( ) ;
104+ // The valtree of the base type is the same as the valtree of the pattern type.
105+ // Since the returned valtree does not contain the type or layout, we can just
106+ // switch to the base type.
107+ place. layout = ecx. layout_of ( * base) . unwrap ( ) ;
108+ ensure_sufficient_stack ( || const_to_valtree_inner ( ecx, & place, num_nodes) )
109+ } ,
110+
111+
101112 ty:: RawPtr ( _, _) => {
102113 // Not all raw pointers are allowed, as we cannot properly test them for
103114 // equality at compile-time (see `ptr_guaranteed_cmp`).
@@ -273,7 +284,7 @@ pub fn valtree_to_const_value<'tcx>(
273284
274285 let ( param_env, ty) = param_env_ty. into_parts ( ) ;
275286
276- match ty. kind ( ) {
287+ match * ty. kind ( ) {
277288 ty:: FnDef ( ..) => {
278289 assert ! ( valtree. unwrap_branch( ) . is_empty( ) ) ;
279290 mir:: ConstValue :: ZeroSized
@@ -286,10 +297,11 @@ pub fn valtree_to_const_value<'tcx>(
286297 ) ,
287298 }
288299 }
300+ ty:: Pat ( ty, _) => valtree_to_const_value ( tcx, param_env. and ( ty) , valtree) ,
289301 ty:: Ref ( _, inner_ty, _) => {
290302 let mut ecx =
291303 mk_eval_cx_to_read_const_val ( tcx, DUMMY_SP , param_env, CanAccessMutGlobal :: No ) ;
292- let imm = valtree_to_ref ( & mut ecx, valtree, * inner_ty) ;
304+ let imm = valtree_to_ref ( & mut ecx, valtree, inner_ty) ;
293305 let imm = ImmTy :: from_immediate ( imm, tcx. layout_of ( param_env_ty) . unwrap ( ) ) ;
294306 op_to_const ( & ecx, & imm. into ( ) , /* for diagnostics */ false )
295307 }
0 commit comments