Auto merge of #120131 - oli-obk:pattern_types_syntax, r=compiler-errors · rust-lang/rust@537aab7 (original) (raw)
``
1
`+
use rustc_data_structures::stack::ensure_sufficient_stack;
`
1
2
`use rustc_middle::mir;
`
2
3
`use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId};
`
3
4
`use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
`
`@@ -98,6 +99,16 @@ fn const_to_valtree_inner<'tcx>(
`
98
99
`Ok(ty::ValTree::Leaf(val.assert_int()))
`
99
100
`}
`
100
101
``
``
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
+
101
112
` ty::RawPtr(_, _) => {
`
102
113
`// Not all raw pointers are allowed, as we cannot properly test them for
`
103
114
`` // equality at compile-time (see ptr_guaranteed_cmp
).
``
`@@ -273,7 +284,7 @@ pub fn valtree_to_const_value<'tcx>(
`
273
284
``
274
285
`let (param_env, ty) = param_env_ty.into_parts();
`
275
286
``
276
``
`-
match ty.kind() {
`
``
287
`+
match *ty.kind() {
`
277
288
` ty::FnDef(..) => {
`
278
289
`assert!(valtree.unwrap_branch().is_empty());
`
279
290
` mir::ConstValue::ZeroSized
`
`@@ -286,10 +297,11 @@ pub fn valtree_to_const_value<'tcx>(
`
286
297
`),
`
287
298
`}
`
288
299
`}
`
``
300
`+
ty::Pat(ty, _) => valtree_to_const_value(tcx, param_env.and(ty), valtree),
`
289
301
` ty::Ref(_, inner_ty, _) => {
`
290
302
`let mut ecx =
`
291
303
`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);
`
293
305
`let imm = ImmTy::from_immediate(imm, tcx.layout_of(param_env_ty).unwrap());
`
294
306
`op_to_const(&ecx, &imm.into(), /* for diagnostics */ false)
`
295
307
`}
`