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
296 changes: 172 additions & 124 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:9:1
|
LL | 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:9:1
|
LL | const A: u8 = A;
| ^^^^^^^^^^^

error: aborting due to 1 previous error

7 changes: 6 additions & 1 deletion tests/ui/const-generics/mgca/type_const-recursive.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//@ 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]
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() {}
18 changes: 18 additions & 0 deletions tests/ui/const-generics/type-const-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ compile-flags: -Znext-solver=globally
#![feature(generic_const_items, min_generic_const_args)]
#![allow(incomplete_features)]

trait Owner {
#[type_const]
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]
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:7:5
|
LL | const C<const N: u32>: u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

38 changes: 38 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(());
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@ compile-flags: -Znext-solver=globally
#![feature(generic_const_items, min_generic_const_args)]
#![feature(adt_const_params)]
#![allow(incomplete_features)]
#![allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

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

This is implied in UI tests.

Suggested change
#![allow(dead_code)]


trait Owner: NewTrait {
#[type_const]
const C<const N: u32>: u32;
#[type_const]
const K<const N: u32>: u32;
}

trait NewTrait {}

impl NewTrait for () {}
Copy link
Member

Choose a reason for hiding this comment

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

By adding this impl, this test doesn't reproduce the ICE on nightly/main.

Suggested change
impl NewTrait for () {}


impl Owner for () {
#[type_const]
const C<const N: u32>: u32 = N;
#[type_const]
const K<const N: u32>: u32 = const { 99 + 1 };
}

fn take0<const N: u32>(_: impl Owner<C<N> = { N }>) {}
fn take1(_: impl Owner<K<99> = 100>) {}

#[derive(PartialEq, Eq, std::marker::ConstParamTy)]
enum Maybe<T> {
Nothing,
Just(T),
}

fn main() {
take0::<128>(());
take1(());
//~^ ERROR type mismatch resolving `const { 99 + 1 } == 100`
}
17 changes: 17 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,17 @@
error[E0271]: type mismatch resolving `const { 99 + 1 } == 100`
--> $DIR/type-const-ice-issue-151631.rs:36:11
|
LL | take1(());
| ----- ^^ types differ
| |
| required by a bound introduced by this call
|
note: required by a bound in `take1`
--> $DIR/type-const-ice-issue-151631.rs:26:24
|
LL | fn take1(_: impl Owner<K<99> = 100>) {}
| ^^^^^^^^^^^ required by this bound in `take1`

error: aborting due to 1 previous error

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