Skip to content

Commit e853189

Browse files
committed
guard recursive type-const evaluation
1 parent 06d80a3 commit e853189

6 files changed

Lines changed: 207 additions & 139 deletions

File tree

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 166 additions & 137 deletions
Large diffs are not rendered by default.

tests/ui/const-generics/mgca/type_const-recursive.stderr renamed to tests/ui/const-generics/mgca/type_const-recursive.current.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0275]: overflow normalizing the unevaluated constant `A`
2-
--> $DIR/type_const-recursive.rs:5:1
2+
--> $DIR/type_const-recursive.rs:9:1
33
|
44
LL | const A: u8 = A;
55
| ^^^^^^^^^^^
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: cycle detected when evaluating type-level constant
2+
--> $DIR/type_const-recursive.rs:9:1
3+
|
4+
LL | const A: u8 = A;
5+
| ^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
15
#![expect(incomplete_features)]
26
#![feature(min_generic_const_args)]
37

48
#[type_const]
59
const A: u8 = A;
6-
//~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275]
10+
//[current]~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275]
11+
//[next]~^^ ERROR cycle detected when evaluating type-level constant
712

813
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: -Znext-solver=globally
2+
#![feature(generic_const_items, min_generic_const_args)]
3+
#![allow(incomplete_features)]
4+
5+
trait Owner {
6+
#[type_const]
7+
const C<const N: u32>: u32;
8+
//~^ ERROR cycle detected when evaluating type-level constant
9+
}
10+
11+
impl Owner for () {
12+
#[type_const]
13+
const C<const N: u32>: u32 = { <() as Owner>::C::<N> };
14+
}
15+
16+
type Arr = [u8; <() as Owner>::C::<0>];
17+
18+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: cycle detected when evaluating type-level constant
2+
--> $DIR/type-const-cycle.rs:7:5
3+
|
4+
LL | const C<const N: u32>: u32;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)