From f4261772d8d4e2d4fb7e9dd4685b995a7176e506 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 27 Jan 2021 14:46:43 +0000 Subject: [PATCH] comments --- .../rustc_trait_selection/src/traits/const_evaluatable.rs | 4 +++- .../const_evaluatable_checked/nested-abstract-consts-1.rs | 2 ++ .../const_evaluatable_checked/nested-abstract-consts-2.rs | 2 ++ .../const_evaluatable_checked/nested_uneval_unification-1.rs | 2 ++ .../const_evaluatable_checked/nested_uneval_unification-2.rs | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 272588ad516c2..b587ed6487e3c 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -612,6 +612,9 @@ pub(super) fn try_unify<'tcx>( mut a: AbstractConst<'tcx>, mut b: AbstractConst<'tcx>, ) -> bool { + // We substitute generics repeatedly to allow AbstractConsts to unify where a + // ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g. + // Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])] while let Node::Leaf(a_ct) = a.root() { let a_ct = a_ct.subst(tcx, a.substs); match AbstractConst::from_const(tcx, a_ct) { @@ -620,7 +623,6 @@ pub(super) fn try_unify<'tcx>( Err(_) => return true, } } - while let Node::Leaf(b_ct) = b.root() { let b_ct = b_ct.subst(tcx, b.substs); match AbstractConst::from_const(tcx, b_ct) { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs b/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs index 124cd317da565..0fe84c1cd2a72 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs +++ b/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs @@ -20,3 +20,5 @@ where fn main() { assert_eq!(caller::<4>(), 5); } + +// Test that the ``(N1 + 1) + 1`` bound on ``caller`` satisfies the ``M2 + 1`` bound on ``callee`` diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs b/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs index 5936662dadb20..fe5c2237a7603 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs +++ b/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs @@ -30,3 +30,5 @@ where fn main() { assert_eq!((Generic::<10>).bar(), 11); } + +// Test that the ``ConstU64<{ K + 1 - 1}>`` bound on ``bar``'s impl block satisfies the ``ConstU64<{K - 1}>`` bound on ``foo``'s impl block diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs b/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs index ff0f2efaee9cb..f686bfd1d2b02 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs +++ b/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs @@ -30,3 +30,5 @@ where fn main() { assert_eq!(substs3::<2>().0, [0; 3]); } + +// Test that the ``{ (L - 1) * 2 + 1 }`` bound on ``substs3`` satisfies the ``{ N + 1 }`` bound on ``Substs1`` diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs b/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs index 806f7ba920310..4cdfb107417a6 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs +++ b/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs @@ -24,3 +24,5 @@ fn substs3() -> Substs1<{ (L) }> { fn main() { assert_eq!(substs3::<2>().0, [0; 2]); } + +// Test that the implicit ``{ (L) }`` bound on ``substs3`` satisfies the ``{ (N) }`` bound on ``Substs1``