@@ -512,6 +512,13 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
512
512
block = & self . body . basic_blocks ( ) [ next] ;
513
513
} else {
514
514
assert_eq ! ( self . locals[ mir:: RETURN_PLACE ] , self . nodes. last( ) . unwrap( ) ) ;
515
+ // `AbstractConst`s should not contain any promoteds as they require references which
516
+ // are not allowed.
517
+ assert ! ( !self . nodes. iter( ) . any( |n| matches!(
518
+ n. node,
519
+ Node :: Leaf ( ty:: Const { val: ty:: ConstKind :: Unevaluated ( _, _, Some ( _) ) , ty: _ } )
520
+ ) ) ) ;
521
+
515
522
self . nodes [ self . locals [ mir:: RETURN_PLACE ] ] . used = true ;
516
523
if let Some ( & unused) = self . nodes . iter ( ) . find ( |n| !n. used ) {
517
524
self . error ( Some ( unused. span ) , "dead code" ) ?;
@@ -609,6 +616,10 @@ pub(super) fn try_unify<'tcx>(
609
616
( Node :: Leaf ( a_ct) , Node :: Leaf ( b_ct) ) => {
610
617
let a_ct = a_ct. subst ( tcx, a. substs ) ;
611
618
let b_ct = b_ct. subst ( tcx, b. substs ) ;
619
+ if a_ct. ty != b_ct. ty {
620
+ return false ;
621
+ }
622
+
612
623
match ( a_ct. val , b_ct. val ) {
613
624
// We can just unify errors with everything to reduce the amount of
614
625
// emitted errors here.
@@ -621,6 +632,12 @@ pub(super) fn try_unify<'tcx>(
621
632
// we do not want to use `assert_eq!(a(), b())` to infer that `N` and `M` have to be `1`. This
622
633
// means that we only allow inference variables if they are equal.
623
634
( ty:: ConstKind :: Infer ( a_val) , ty:: ConstKind :: Infer ( b_val) ) => a_val == b_val,
635
+ // We may want to instead recurse into unevaluated constants here. That may require some
636
+ // care to prevent infinite recursion, so let's just ignore this for now.
637
+ (
638
+ ty:: ConstKind :: Unevaluated ( a_def, a_substs, None ) ,
639
+ ty:: ConstKind :: Unevaluated ( b_def, b_substs, None ) ,
640
+ ) => a_def == b_def && a_substs == b_substs,
624
641
// FIXME(const_evaluatable_checked): We may want to either actually try
625
642
// to evaluate `a_ct` and `b_ct` if they are are fully concrete or something like
626
643
// this, for now we just return false here.
0 commit comments