-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #81426 - BoxyUwU:boxychangesv2, r=oli-obk
const_evaluatable: expand abstract consts in try_unify See this [zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/combining.20const.20bounds) for more info cc ```@lcnr``` r? ```@oli-obk```
- Loading branch information
Showing
5 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-pass | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
fn callee<const M2: usize>() -> usize | ||
where | ||
[u8; M2 + 1]: Sized, | ||
{ | ||
M2 | ||
} | ||
|
||
fn caller<const N1: usize>() -> usize | ||
where | ||
[u8; N1 + 1]: Sized, | ||
[u8; (N1 + 1) + 1]: Sized, | ||
{ | ||
callee::<{ N1 + 1 }>() | ||
} | ||
|
||
fn main() { | ||
assert_eq!(caller::<4>(), 5); | ||
} | ||
|
||
// Test that the ``(N1 + 1) + 1`` bound on ``caller`` satisfies the ``M2 + 1`` bound on ``callee`` |
35 changes: 35 additions & 0 deletions
35
src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-pass | ||
#![feature(const_evaluatable_checked, const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
struct Generic<const K: u64>; | ||
|
||
struct ConstU64<const K: u64>; | ||
|
||
impl<const K: u64> Generic<K> | ||
where | ||
ConstU64<{ K - 1 }>: , | ||
{ | ||
fn foo(self) -> u64 { | ||
K | ||
} | ||
} | ||
|
||
impl<const K: u64> Generic<K> | ||
where | ||
ConstU64<{ K - 1 }>: , | ||
ConstU64<{ K + 1 }>: , | ||
ConstU64<{ K + 1 - 1 }>: , | ||
{ | ||
fn bar(self) -> u64 { | ||
let x: Generic<{ K + 1 }> = Generic; | ||
x.foo() | ||
} | ||
} | ||
|
||
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 |
35 changes: 35 additions & 0 deletions
35
src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-pass | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
fn zero_init<const N: usize>() -> Substs1<N> | ||
where | ||
[u8; N + 1]: , | ||
{ | ||
Substs1([0; N + 1]) | ||
} | ||
struct Substs1<const N: usize>([u8; N + 1]) | ||
where | ||
[(); N + 1]: ; | ||
|
||
fn substs2<const M: usize>() -> Substs1<{ M * 2 }> | ||
where | ||
[(); { M * 2 } + 1]: , | ||
{ | ||
zero_init::<{ M * 2 }>() | ||
} | ||
|
||
fn substs3<const L: usize>() -> Substs1<{ (L - 1) * 2 }> | ||
where | ||
[(); (L - 1)]: , | ||
[(); (L - 1) * 2 + 1]: , | ||
{ | ||
substs2::<{ L - 1 }>() | ||
} | ||
|
||
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`` |
29 changes: 29 additions & 0 deletions
29
src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// run-pass | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features, unused_parens, unused_braces)] | ||
|
||
fn zero_init<const N: usize>() -> Substs1<{ (N) }> | ||
where | ||
[u8; { (N) }]: , | ||
{ | ||
Substs1([0; { (N) }]) | ||
} | ||
|
||
struct Substs1<const N: usize>([u8; { (N) }]) | ||
where | ||
[(); { (N) }]: ; | ||
|
||
fn substs2<const M: usize>() -> Substs1<{ (M) }> { | ||
zero_init::<{ (M) }>() | ||
} | ||
|
||
fn substs3<const L: usize>() -> Substs1<{ (L) }> { | ||
substs2::<{ (L) }>() | ||
} | ||
|
||
fn main() { | ||
assert_eq!(substs3::<2>().0, [0; 2]); | ||
} | ||
|
||
// Test that the implicit ``{ (L) }`` bound on ``substs3`` satisfies the | ||
// ``{ (N) }`` bound on ``Substs1`` |