@@ -304,12 +304,11 @@ use std::iter::{FromIterator, IntoIterator};
304
304
use std:: ops:: RangeInclusive ;
305
305
306
306
crate 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)
308
308
}
309
309
310
310
struct LiteralExpander < ' tcx > {
311
311
tcx : TyCtxt < ' tcx > ,
312
- param_env : ty:: ParamEnv < ' tcx > ,
313
312
}
314
313
315
314
impl < ' tcx > LiteralExpander < ' tcx > {
@@ -328,40 +327,17 @@ impl<'tcx> LiteralExpander<'tcx> {
328
327
) -> ConstValue < ' tcx > {
329
328
debug ! ( "fold_const_value_deref {:?} {:?} {:?}" , val, rty, crty) ;
330
329
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
- }
350
330
// unsize array to slice if pattern is array but match value or other patterns are slice
351
331
( ConstValue :: Scalar ( Scalar :: Ptr ( p) ) , ty:: Array ( t, n) , ty:: Slice ( u) ) => {
352
332
assert_eq ! ( t, u) ;
333
+ assert_eq ! ( p. offset, Size :: ZERO ) ;
353
334
ConstValue :: Slice {
354
335
data : self . tcx . global_alloc ( p. alloc_id ) . unwrap_memory ( ) ,
355
- start : p . offset . bytes ( ) . try_into ( ) . unwrap ( ) ,
336
+ start : 0 ,
356
337
end : n. eval_usize ( self . tcx , ty:: ParamEnv :: empty ( ) ) . try_into ( ) . unwrap ( ) ,
357
338
}
358
339
}
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,
365
341
}
366
342
}
367
343
}
0 commit comments