Skip to content

Commit 1641602

Browse files
committed
guard recursive type-const evaluation
1 parent 3587bf8 commit 1641602

8 files changed

Lines changed: 259 additions & 194 deletions

File tree

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 177 additions & 148 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:8:1
33
|
44
LL | type 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:8:1
3+
|
4+
LL | type const A: u8 = A;
5+
| ^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
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

4-
58
type const A: u8 = A;
6-
//~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275]
9+
//[current]~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275]
10+
//[next]~^^ ERROR cycle detected when evaluating type-level constant
711

812
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 C<const N: u32>: u32;
7+
//~^ ERROR cycle detected when evaluating type-level constant
8+
}
9+
10+
impl Owner for () {
11+
type const C<const N: u32>: u32 = { <() as Owner>::C::<N> };
12+
}
13+
14+
type Arr = [u8; <() as Owner>::C::<0>];
15+
16+
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:6:5
3+
|
4+
LL | type const C<const N: u32>: u32;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
1-
//@ compile-flags: -Znext-solver=globally
2-
#![feature(generic_const_items, min_generic_const_args)]
3-
#![feature(adt_const_params)]
4-
#![allow(incomplete_features)]
5-
#![allow(dead_code)]
1+
// issue: <https://github.com/rust-lang/rust/issues/151631>
2+
//@ compile-flags: -Znext-solver
3+
#![feature(min_generic_const_args)]
4+
#![expect(incomplete_features)]
65

7-
trait Owner: NewTrait {
8-
#[type_const]
9-
const C<const N: u32>: u32;
10-
#[type_const]
11-
const K<const N: u32>: u32;
6+
trait SuperTrait {}
7+
trait Trait: SuperTrait {
8+
type const K: u32;
129
}
13-
14-
trait NewTrait {}
15-
16-
impl NewTrait for () {}
17-
18-
impl Owner for () {
19-
#[type_const]
20-
const C<const N: u32>: u32 = N;
21-
#[type_const]
22-
const K<const N: u32>: u32 = const { 99 + 1 };
10+
impl Trait for () { //~ ERROR: the trait bound `(): SuperTrait` is not satisfied
11+
type const K: u32 = const { 1 };
2312
}
2413

25-
fn take0<const N: u32>(_: impl Owner<C<N> = { N }>) {}
26-
fn take1(_: impl Owner<K<99> = 100>) {}
27-
28-
#[derive(PartialEq, Eq, std::marker::ConstParamTy)]
29-
enum Maybe<T> {
30-
Nothing,
31-
Just(T),
32-
}
14+
fn check(_: impl Trait<K = 0>) {}
3315

3416
fn main() {
35-
take0::<128>(());
36-
take1(());
37-
//~^ ERROR type mismatch resolving `const { 99 + 1 } == 100`
17+
check(()); //~ ERROR: the trait bound `(): SuperTrait` is not satisfied
3818
}
Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
1-
error[E0271]: type mismatch resolving `const { 99 + 1 } == 100`
2-
--> $DIR/type-const-ice-issue-151631.rs:36:11
1+
error[E0277]: the trait bound `(): SuperTrait` is not satisfied
2+
--> $DIR/type-const-ice-issue-151631.rs:10:16
33
|
4-
LL | take1(());
5-
| ----- ^^ types differ
6-
| |
7-
| required by a bound introduced by this call
4+
LL | impl Trait for () {
5+
| ^^ the trait `SuperTrait` is not implemented for `()`
86
|
9-
note: required by a bound in `take1`
10-
--> $DIR/type-const-ice-issue-151631.rs:26:24
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/type-const-ice-issue-151631.rs:6:1
119
|
12-
LL | fn take1(_: impl Owner<K<99> = 100>) {}
13-
| ^^^^^^^^^^^ required by this bound in `take1`
10+
LL | trait SuperTrait {}
11+
| ^^^^^^^^^^^^^^^^
12+
note: required by a bound in `Trait`
13+
--> $DIR/type-const-ice-issue-151631.rs:7:14
14+
|
15+
LL | trait Trait: SuperTrait {
16+
| ^^^^^^^^^^ required by this bound in `Trait`
17+
18+
error[E0277]: the trait bound `(): SuperTrait` is not satisfied
19+
--> $DIR/type-const-ice-issue-151631.rs:17:5
20+
|
21+
LL | check(());
22+
| ^^^^^^^^^ the trait `SuperTrait` is not implemented for `()`
23+
|
24+
help: this trait has no implementations, consider adding one
25+
--> $DIR/type-const-ice-issue-151631.rs:6:1
26+
|
27+
LL | trait SuperTrait {}
28+
| ^^^^^^^^^^^^^^^^
29+
note: required by a bound in `Trait`
30+
--> $DIR/type-const-ice-issue-151631.rs:7:14
31+
|
32+
LL | trait Trait: SuperTrait {
33+
| ^^^^^^^^^^ required by this bound in `Trait`
1434

15-
error: aborting due to 1 previous error
35+
error: aborting due to 2 previous errors
1636

17-
For more information about this error, try `rustc --explain E0271`.
37+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)