From 019dba0cebac1944c74644ba7365490ef3a8c753 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 2 Mar 2021 11:22:37 +0000 Subject: [PATCH] Resolve a FIXME around type equality checks in Relate for constants --- compiler/rustc_middle/src/ty/relate.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index f21545447b20..fef8be57344f 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -498,12 +498,15 @@ pub fn super_relate_consts>( debug!("{}.super_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b); let tcx = relation.tcx(); - let eagerly_eval = |x: &'tcx ty::Const<'tcx>| x.eval(tcx, relation.param_env()).val; + // FIXME(oli-obk): once const generics can have generic types, this assertion + // will likely get triggered. Move to `normalize_erasing_regions` at that point. + assert_eq!( + tcx.erase_regions(a.ty), + tcx.erase_regions(b.ty), + "cannot relate constants of different types" + ); - // FIXME(eddyb) doesn't look like everything below checks that `a.ty == b.ty`. - // We could probably always assert it early, as const generic parameters - // are not allowed to depend on other generic parameters, i.e. are concrete. - // (although there could be normalization differences) + let eagerly_eval = |x: &'tcx ty::Const<'tcx>| x.eval(tcx, relation.param_env()).val; // Currently, the values that can be unified are primitive types, // and those that derive both `PartialEq` and `Eq`, corresponding @@ -524,7 +527,7 @@ pub fn super_relate_consts>( } (ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => { let new_val = match (a_val, b_val) { - (ConstValue::Scalar(a_val), ConstValue::Scalar(b_val)) if a.ty == b.ty => { + (ConstValue::Scalar(a_val), ConstValue::Scalar(b_val)) => { if a_val == b_val { Ok(ConstValue::Scalar(a_val)) } else if let ty::FnPtr(_) = a.ty.kind() {