@@ -49,6 +49,9 @@ pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Sized {
4949 ecx : & InterpCx < ' mir , ' tcx , M > ,
5050 field : usize ,
5151 ) -> InterpResult < ' tcx , Self > ;
52+
53+ /// Strip a layer of pattern types to get at the inner type
54+ fn strip_pat_ty ( self ) -> Self ;
5255}
5356
5457/// A thing that we can project into given *mutable* access to `ecx`, and that has a layout.
@@ -88,6 +91,9 @@ pub trait ValueMut<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Sized {
8891 ecx : & mut InterpCx < ' mir , ' tcx , M > ,
8992 field : usize ,
9093 ) -> InterpResult < ' tcx , Self > ;
94+
95+ /// Strip a layer of pattern types to get at the inner type
96+ fn strip_pat_ty ( self ) -> Self ;
9197}
9298
9399// We cannot have a general impl which shows that Value implies ValueMut. (When we do, it says we
@@ -131,6 +137,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tc
131137 ) -> InterpResult < ' tcx , Self > {
132138 ecx. operand_field ( self , field)
133139 }
140+
141+ #[ inline( always) ]
142+ fn strip_pat_ty ( mut self ) -> Self {
143+ let ty:: Pat ( raw_ptr_ty, _) = * self . layout . ty . kind ( ) else {
144+ bug ! ( "NonNull must contain a pattern type, but had {}" , self . layout. ty)
145+ } ;
146+ self . layout . ty = raw_ptr_ty;
147+ self
148+ }
134149}
135150
136151impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > ValueMut < ' mir , ' tcx , M >
@@ -179,6 +194,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueMut<'mir, 'tcx, M>
179194 ) -> InterpResult < ' tcx , Self > {
180195 ecx. operand_field ( self , field)
181196 }
197+
198+ #[ inline( always) ]
199+ fn strip_pat_ty ( mut self ) -> Self {
200+ let ty:: Pat ( raw_ptr_ty, _) = * self . layout . ty . kind ( ) else {
201+ bug ! ( "NonNull must contain a pattern type, but had {}" , self . layout. ty)
202+ } ;
203+ self . layout . ty = raw_ptr_ty;
204+ self
205+ }
182206}
183207
184208impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > Value < ' mir , ' tcx , M >
@@ -220,6 +244,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M>
220244 ) -> InterpResult < ' tcx , Self > {
221245 ecx. mplace_field ( self , field)
222246 }
247+
248+ #[ inline( always) ]
249+ fn strip_pat_ty ( mut self ) -> Self {
250+ let ty:: Pat ( raw_ptr_ty, _) = * self . layout . ty . kind ( ) else {
251+ bug ! ( "NonNull must contain a pattern type, but had {}" , self . layout. ty)
252+ } ;
253+ self . layout . ty = raw_ptr_ty;
254+ self
255+ }
223256}
224257
225258impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > ValueMut < ' mir , ' tcx , M >
@@ -269,6 +302,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueMut<'mir, 'tcx, M>
269302 ) -> InterpResult < ' tcx , Self > {
270303 ecx. mplace_field ( self , field)
271304 }
305+
306+ #[ inline( always) ]
307+ fn strip_pat_ty ( mut self ) -> Self {
308+ let ty:: Pat ( raw_ptr_ty, _) = * self . layout . ty . kind ( ) else {
309+ bug ! ( "NonNull must contain a pattern type, but had {}" , self . layout. ty)
310+ } ;
311+ self . layout . ty = raw_ptr_ty;
312+ self
313+ }
272314}
273315
274316impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > ValueMut < ' mir , ' tcx , M >
@@ -320,6 +362,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueMut<'mir, 'tcx, M>
320362 ) -> InterpResult < ' tcx , Self > {
321363 ecx. place_field ( self , field)
322364 }
365+
366+ #[ inline( always) ]
367+ fn strip_pat_ty ( mut self ) -> Self {
368+ let ty:: Pat ( raw_ptr_ty, _) = * self . layout . ty . kind ( ) else {
369+ bug ! ( "NonNull must contain a pattern type, but had {}" , self . layout. ty)
370+ } ;
371+ self . layout . ty = raw_ptr_ty;
372+ self
373+ }
323374}
324375
325376macro_rules! make_value_visitor {
@@ -466,7 +517,7 @@ macro_rules! make_value_visitor {
466517 ) ;
467518 // ... that contains a `NonNull`... (gladly, only a single field here)
468519 assert_eq!( nonnull_ptr. layout( ) . fields. count( ) , 1 ) ;
469- let raw_ptr = nonnull_ptr. project_field( self . ecx( ) , 0 ) ?; // the actual raw ptr
520+ let raw_ptr = nonnull_ptr. project_field( self . ecx( ) , 0 ) ?. strip_pat_ty ( ) ; // the actual raw ptr
470521 // ... whose only field finally is a raw ptr we can dereference.
471522 self . visit_box( & raw_ptr) ?;
472523
0 commit comments