@@ -11,6 +11,7 @@ use crate::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
11
11
use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
12
12
use rustc_hir as ast;
13
13
use rustc_hir:: def_id:: DefId ;
14
+ use rustc_span:: DUMMY_SP ;
14
15
use rustc_target:: spec:: abi;
15
16
use std:: iter;
16
17
use std:: rc:: Rc ;
@@ -507,6 +508,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
507
508
a : & ' tcx ty:: Const < ' tcx > ,
508
509
b : & ' tcx ty:: Const < ' tcx > ,
509
510
) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
511
+ debug ! ( "{}.super_relate_consts(a = {:?}, b = {:?})" , relation. tag( ) , a, b) ;
510
512
let tcx = relation. tcx ( ) ;
511
513
512
514
let eagerly_eval = |x : & ' tcx ty:: Const < ' tcx > | {
@@ -561,7 +563,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
561
563
}
562
564
}
563
565
564
- ( a_val @ ConstValue :: Slice { .. } , b_val @ ConstValue :: Slice { .. } ) => {
566
+ ( ConstValue :: Slice { .. } , ConstValue :: Slice { .. } ) => {
565
567
let a_bytes = get_slice_bytes ( & tcx, a_val) ;
566
568
let b_bytes = get_slice_bytes ( & tcx, b_val) ;
567
569
if a_bytes == b_bytes {
@@ -571,7 +573,37 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
571
573
}
572
574
}
573
575
574
- // FIXME(const_generics): handle `ConstValue::ByRef`.
576
+ ( ConstValue :: ByRef { .. } , ConstValue :: ByRef { .. } ) => {
577
+ match a. ty . kind {
578
+ ty:: Array ( ..) | ty:: Adt ( ..) | ty:: Tuple ( ..) => {
579
+ let a_destructured = tcx. destructure_const ( relation. param_env ( ) . and ( a) ) ;
580
+ let b_destructured = tcx. destructure_const ( relation. param_env ( ) . and ( b) ) ;
581
+
582
+ // Both the variant and each field have to be equal.
583
+ if a_destructured. variant == b_destructured. variant {
584
+ for ( a_field, b_field) in
585
+ a_destructured. fields . iter ( ) . zip ( b_destructured. fields . iter ( ) )
586
+ {
587
+ relation. consts ( a_field, b_field) ?;
588
+ }
589
+
590
+ Ok ( a_val)
591
+ } else {
592
+ Err ( TypeError :: ConstMismatch ( expected_found ( relation, & a, & b) ) )
593
+ }
594
+ }
595
+ // FIXME(const_generics): There are probably some `TyKind`s
596
+ // which should be handled here.
597
+ _ => {
598
+ tcx. sess . delay_span_bug (
599
+ DUMMY_SP ,
600
+ & format ! ( "unexpected consts: a: {:?}, b: {:?}" , a, b) ,
601
+ ) ;
602
+ Err ( TypeError :: ConstMismatch ( expected_found ( relation, & a, & b) ) )
603
+ }
604
+ }
605
+ }
606
+
575
607
_ => Err ( TypeError :: ConstMismatch ( expected_found ( relation, & a, & b) ) ) ,
576
608
} ;
577
609
0 commit comments