@@ -313,7 +313,10 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
313313 (
314314 & ty:: Ref ( _, rty, _) ,
315315 & PatKind :: Constant {
316- value : Const { val, ty : ty:: TyS { kind : ty:: Ref ( _, crty, _) , .. } } ,
316+ value : Const {
317+ val : ty:: ConstKind :: Value ( val) ,
318+ ty : ty:: TyS { kind : ty:: Ref ( _, crty, _) , .. }
319+ } ,
317320 } ,
318321 ) => Pat {
319322 ty : pat. ty ,
@@ -324,13 +327,21 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
324327 span : pat. span ,
325328 kind : box PatKind :: Constant {
326329 value : self . tcx . mk_const ( Const {
327- val : self . fold_const_value_deref ( * val, rty, crty) ,
330+ val : ty :: ConstKind :: Value ( self . fold_const_value_deref ( * val, rty, crty) ) ,
328331 ty : rty,
329332 } ) ,
330333 } ,
331334 } ,
332335 } ,
333336 } ,
337+
338+ (
339+ & ty:: Ref ( _, rty, _) ,
340+ & PatKind :: Constant {
341+ value : Const { val, ty : ty:: TyS { kind : ty:: Ref ( _, crty, _) , .. } } ,
342+ } ,
343+ ) => bug ! ( "cannot deref {:#?}, {} -> {}" , val, crty, rty) ,
344+
334345 ( _, & PatKind :: Binding { subpattern : Some ( ref s) , .. } ) => s. fold_with ( self ) ,
335346 _ => pat. super_fold_with ( self ) ,
336347 }
@@ -1245,7 +1256,7 @@ impl<'tcx> IntRange<'tcx> {
12451256 ) -> Option < IntRange < ' tcx > > {
12461257 if let Some ( ( target_size, bias) ) = Self :: integral_size_and_signed_bias ( tcx, value. ty ) {
12471258 let ty = value. ty ;
1248- let val = if let ConstValue :: Scalar ( Scalar :: Raw { data, size } ) = value. val {
1259+ let val = if let ty :: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Raw { data, size } ) ) = value. val {
12491260 // For this specific pattern we can skip a lot of effort and go
12501261 // straight to the result, after doing a bit of checking. (We
12511262 // could remove this branch and just use the next branch, which
@@ -1781,7 +1792,19 @@ fn slice_pat_covered_by_const<'tcx>(
17811792 suffix : & [ Pat < ' tcx > ] ,
17821793 param_env : ty:: ParamEnv < ' tcx > ,
17831794) -> Result < bool , ErrorReported > {
1784- let data: & [ u8 ] = match ( const_val. val , & const_val. ty . kind ) {
1795+ let const_val_val = if let ty:: ConstKind :: Value ( val) = const_val. val {
1796+ val
1797+ } else {
1798+ bug ! (
1799+ "slice_pat_covered_by_const: {:#?}, {:#?}, {:#?}, {:#?}" ,
1800+ const_val,
1801+ prefix,
1802+ slice,
1803+ suffix,
1804+ )
1805+ } ;
1806+
1807+ let data: & [ u8 ] = match ( const_val_val, & const_val. ty . kind ) {
17851808 ( ConstValue :: ByRef { offset, alloc, .. } , ty:: Array ( t, n) ) => {
17861809 assert_eq ! ( * t, tcx. types. u8 ) ;
17871810 let n = n. eval_usize ( tcx, param_env) ;
@@ -2054,7 +2077,8 @@ fn split_grouped_constructors<'p, 'tcx>(
20542077 max_fixed_len =
20552078 cmp:: max ( max_fixed_len, n. eval_usize ( tcx, param_env) )
20562079 }
2057- ( ConstValue :: Slice { start, end, .. } , ty:: Slice ( _) ) => {
2080+ ( ty:: ConstKind :: Value ( ConstValue :: Slice { start, end, .. } ) ,
2081+ ty:: Slice ( _) ) => {
20582082 max_fixed_len = cmp:: max ( max_fixed_len, ( end - start) as u64 )
20592083 }
20602084 _ => { }
@@ -2253,17 +2277,17 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
22532277 // is when they are subslices of nonzero slices.
22542278 let ( alloc, offset, n, ty) = match value. ty . kind {
22552279 ty:: Array ( t, n) => match value. val {
2256- ConstValue :: ByRef { offset, alloc, .. } => {
2280+ ty :: ConstKind :: Value ( ConstValue :: ByRef { offset, alloc, .. } ) => {
22572281 ( alloc, offset, n. eval_usize ( cx. tcx , cx. param_env ) , t)
22582282 }
22592283 _ => span_bug ! ( pat. span, "array pattern is {:?}" , value, ) ,
22602284 } ,
22612285 ty:: Slice ( t) => {
22622286 match value. val {
2263- ConstValue :: Slice { data, start, end } => {
2287+ ty :: ConstKind :: Value ( ConstValue :: Slice { data, start, end } ) => {
22642288 ( data, Size :: from_bytes ( start as u64 ) , ( end - start) as u64 , t)
22652289 }
2266- ConstValue :: ByRef { .. } => {
2290+ ty :: ConstKind :: Value ( ConstValue :: ByRef { .. } ) => {
22672291 // FIXME(oli-obk): implement `deref` for `ConstValue`
22682292 return None ;
22692293 }
0 commit comments