Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
318 changes: 183 additions & 135 deletions compiler/rustc_trait_selection/src/traits/mod.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0275]: overflow normalizing the unevaluated constant `A`
--> $DIR/type_const-recursive.rs:5:1
--> $DIR/type_const-recursive.rs:8:1
|
LL | type const A: u8 = A;
| ^^^^^^^^^^^^^^^^
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/const-generics/mgca/type_const-recursive.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: cycle detected when evaluating type-level constant
--> $DIR/type_const-recursive.rs:8:1
|
LL | type const A: u8 = A;
| ^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 6 additions & 2 deletions tests/ui/const-generics/mgca/type_const-recursive.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ ignore-compare-mode-next-solver (explicit revisions)

#![expect(incomplete_features)]
#![feature(min_generic_const_args)]


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

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/const-generics/type-const-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ compile-flags: -Znext-solver=globally
#![feature(generic_const_items, min_generic_const_args)]
#![allow(incomplete_features)]

trait Owner {
type const C<const N: u32>: u32;
//~^ ERROR cycle detected when evaluating type-level constant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this error would point to the C in the trait impl.

}

impl Owner for () {
type const C<const N: u32>: u32 = { <() as Owner>::C::<N> };
}

type Arr = [u8; <() as Owner>::C::<0>];

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/const-generics/type-const-cycle.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: cycle detected when evaluating type-level constant
--> $DIR/type-const-cycle.rs:6:5
|
LL | type const C<const N: u32>: u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

18 changes: 18 additions & 0 deletions tests/ui/const-generics/type-const-ice-issue-151631.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't minimized and contains a lot of unrelated elements. Here's a smaller one:

// issue: <https://github.com/rust-lang/rust/issues/151631>
//@ compile-flags: -Znext-solver
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]

trait SuperTrait {}
trait Trait: SuperTrait {
    type const K: u32;
}
impl Trait for () {
    type const K: u32 = const { 1 };
}

fn check(_: impl Trait<K = 0>) {}

fn main() {
    check(());
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I tweaked during developing then forgot to revert. Thank you! Fixed in 1641602.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// issue: <https://github.com/rust-lang/rust/issues/151631>
//@ compile-flags: -Znext-solver
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]

trait SuperTrait {}
trait Trait: SuperTrait {
type const K: u32;
}
impl Trait for () { //~ ERROR: the trait bound `(): SuperTrait` is not satisfied
type const K: u32 = const { 1 };
}

fn check(_: impl Trait<K = 0>) {}

fn main() {
check(()); //~ ERROR: the trait bound `(): SuperTrait` is not satisfied
}
37 changes: 37 additions & 0 deletions tests/ui/const-generics/type-const-ice-issue-151631.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0277]: the trait bound `(): SuperTrait` is not satisfied
--> $DIR/type-const-ice-issue-151631.rs:10:16
|
LL | impl Trait for () {
| ^^ the trait `SuperTrait` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/type-const-ice-issue-151631.rs:6:1
|
LL | trait SuperTrait {}
| ^^^^^^^^^^^^^^^^
note: required by a bound in `Trait`
--> $DIR/type-const-ice-issue-151631.rs:7:14
|
LL | trait Trait: SuperTrait {
| ^^^^^^^^^^ required by this bound in `Trait`

error[E0277]: the trait bound `(): SuperTrait` is not satisfied
--> $DIR/type-const-ice-issue-151631.rs:17:5
|
LL | check(());
| ^^^^^^^^^ the trait `SuperTrait` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/type-const-ice-issue-151631.rs:6:1
|
LL | trait SuperTrait {}
| ^^^^^^^^^^^^^^^^
note: required by a bound in `Trait`
--> $DIR/type-const-ice-issue-151631.rs:7:14
|
LL | trait Trait: SuperTrait {
| ^^^^^^^^^^ required by this bound in `Trait`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
Loading