@@ -304,12 +304,11 @@ use std::iter::{FromIterator, IntoIterator};
304304use std:: ops:: RangeInclusive ;
305305
306306crate fn expand_pattern < ' a , ' tcx > ( cx : & MatchCheckCtxt < ' a , ' tcx > , pat : Pat < ' tcx > ) -> Pat < ' tcx > {
307- LiteralExpander { tcx : cx. tcx , param_env : cx . param_env } . fold_pattern ( & pat)
307+ LiteralExpander { tcx : cx. tcx } . fold_pattern ( & pat)
308308}
309309
310310struct LiteralExpander < ' tcx > {
311311 tcx : TyCtxt < ' tcx > ,
312- param_env : ty:: ParamEnv < ' tcx > ,
313312}
314313
315314impl < ' tcx > LiteralExpander < ' tcx > {
@@ -328,40 +327,17 @@ impl<'tcx> LiteralExpander<'tcx> {
328327 ) -> ConstValue < ' tcx > {
329328 debug ! ( "fold_const_value_deref {:?} {:?} {:?}" , val, rty, crty) ;
330329 match ( val, & crty. kind ( ) , & rty. kind ( ) ) {
331- // the easy case, deref a reference
332- ( ConstValue :: Scalar ( p) , x, y) if x == y => {
333- match p {
334- Scalar :: Ptr ( p) => {
335- let alloc = self . tcx . global_alloc ( p. alloc_id ) . unwrap_memory ( ) ;
336- ConstValue :: ByRef { alloc, offset : p. offset }
337- }
338- Scalar :: Raw { .. } => {
339- let layout = self . tcx . layout_of ( self . param_env . and ( rty) ) . unwrap ( ) ;
340- if layout. is_zst ( ) {
341- // Deref of a reference to a ZST is a nop.
342- ConstValue :: Scalar ( Scalar :: zst ( ) )
343- } else {
344- // FIXME(oli-obk): this is reachable for `const FOO: &&&u32 = &&&42;`
345- bug ! ( "cannot deref {:#?}, {} -> {}" , val, crty, rty) ;
346- }
347- }
348- }
349- }
350330 // unsize array to slice if pattern is array but match value or other patterns are slice
351331 ( ConstValue :: Scalar ( Scalar :: Ptr ( p) ) , ty:: Array ( t, n) , ty:: Slice ( u) ) => {
352332 assert_eq ! ( t, u) ;
333+ assert_eq ! ( p. offset, Size :: ZERO ) ;
353334 ConstValue :: Slice {
354335 data : self . tcx . global_alloc ( p. alloc_id ) . unwrap_memory ( ) ,
355- start : p . offset . bytes ( ) . try_into ( ) . unwrap ( ) ,
336+ start : 0 ,
356337 end : n. eval_usize ( self . tcx , ty:: ParamEnv :: empty ( ) ) . try_into ( ) . unwrap ( ) ,
357338 }
358339 }
359- // fat pointers stay the same
360- ( ConstValue :: Slice { .. } , _, _)
361- | ( _, ty:: Slice ( _) , ty:: Slice ( _) )
362- | ( _, ty:: Str , ty:: Str ) => val,
363- // FIXME(oli-obk): this is reachable for `const FOO: &&&u32 = &&&42;` being used
364- _ => bug ! ( "cannot deref {:#?}, {} -> {}" , val, crty, rty) ,
340+ _ => val,
365341 }
366342 }
367343}
0 commit comments