Skip to content

Commit f426177

Browse files
committed
comments
1 parent b0625eb commit f426177

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ pub(super) fn try_unify<'tcx>(
612612
mut a: AbstractConst<'tcx>,
613613
mut b: AbstractConst<'tcx>,
614614
) -> bool {
615+
// We substitute generics repeatedly to allow AbstractConsts to unify where a
616+
// ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g.
617+
// Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])]
615618
while let Node::Leaf(a_ct) = a.root() {
616619
let a_ct = a_ct.subst(tcx, a.substs);
617620
match AbstractConst::from_const(tcx, a_ct) {
@@ -620,7 +623,6 @@ pub(super) fn try_unify<'tcx>(
620623
Err(_) => return true,
621624
}
622625
}
623-
624626
while let Node::Leaf(b_ct) = b.root() {
625627
let b_ct = b_ct.subst(tcx, b.substs);
626628
match AbstractConst::from_const(tcx, b_ct) {

src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ where
2020
fn main() {
2121
assert_eq!(caller::<4>(), 5);
2222
}
23+
24+
// Test that the ``(N1 + 1) + 1`` bound on ``caller`` satisfies the ``M2 + 1`` bound on ``callee``

src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ where
3030
fn main() {
3131
assert_eq!((Generic::<10>).bar(), 11);
3232
}
33+
34+
// Test that the ``ConstU64<{ K + 1 - 1}>`` bound on ``bar``'s impl block satisfies the ``ConstU64<{K - 1}>`` bound on ``foo``'s impl block

src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ where
3030
fn main() {
3131
assert_eq!(substs3::<2>().0, [0; 3]);
3232
}
33+
34+
// Test that the ``{ (L - 1) * 2 + 1 }`` bound on ``substs3`` satisfies the ``{ N + 1 }`` bound on ``Substs1``

src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ fn substs3<const L: usize>() -> Substs1<{ (L) }> {
2424
fn main() {
2525
assert_eq!(substs3::<2>().0, [0; 2]);
2626
}
27+
28+
// Test that the implicit ``{ (L) }`` bound on ``substs3`` satisfies the ``{ (N) }`` bound on ``Substs1``

0 commit comments

Comments
 (0)