Skip to content

Commit 4085e94

Browse files
BoxyUwUJulianKnodt
authored andcommitted
super_relate_consts do not spurriously fail on assoc consts
1 parent 430f7d1 commit 4085e94

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

compiler/rustc_middle/src/ty/relate.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,15 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
631631
b = b.eval(tcx, relation.param_env());
632632
}
633633

634+
if tcx.features().generic_const_exprs {
635+
if let Ok(Some(a2)) = tcx.expand_abstract_consts(a) {
636+
a = a2;
637+
}
638+
if let Ok(Some(b2)) = tcx.expand_abstract_consts(b) {
639+
b = b2
640+
}
641+
}
642+
634643
// Currently, the values that can be unified are primitive types,
635644
// and those that derive both `PartialEq` and `Eq`, corresponding
636645
// to structural-match types.
@@ -647,22 +656,6 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
647656
(ty::ConstKind::Placeholder(p1), ty::ConstKind::Placeholder(p2)) => p1 == p2,
648657
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => a_val == b_val,
649658

650-
(ty::ConstKind::Unevaluated(_), ty::ConstKind::Unevaluated(_))
651-
if tcx.features().generic_const_exprs =>
652-
{
653-
// FIXME(generic_const_exprs): this spurriously fails when relating two assoc consts
654-
// i.e. `<T as Trait>::ASSOC eq <T as Trait>::ASSOC` would return `false`. Wheras if
655-
// both were behind an anon const that gets normalized away here it would succeed.
656-
if let (Ok(Some(a)), Ok(Some(b))) = (
657-
tcx.expand_abstract_consts(a),
658-
tcx.expand_abstract_consts(b),
659-
) && a.ty() == b.ty() {
660-
return relation.consts(a, b);
661-
} else {
662-
false
663-
}
664-
}
665-
666659
// While this is slightly incorrect, it shouldn't matter for `min_const_generics`
667660
// and is the better alternative to waiting until `generic_const_exprs` can
668661
// be stabilized.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
#![feature(generic_const_exprs)]
3+
#![allow(incomplete_features)]
4+
5+
trait Trait {
6+
const ASSOC: usize;
7+
}
8+
9+
struct Foo<T: Trait>(T)
10+
where
11+
[(); T::ASSOC]:;
12+
13+
impl<T: Trait> Drop for Foo<T>
14+
where
15+
[(); T::ASSOC]:,
16+
{
17+
fn drop(&mut self) {}
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)