-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
trait_selection: fix type-const eval ICE #152040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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 | ||
|
|
| 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() {} |
| 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 | ||
| } | ||
|
|
||
| impl Owner for () { | ||
| #[type_const] | ||
| const C<const N: u32>: u32 = { <() as Owner>::C::<N> }; | ||
| } | ||
|
|
||
| type Arr = [u8; <() as Owner>::C::<0>]; | ||
|
|
||
| fn main() {} | ||
| 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 | ||
|
|
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is implied in UI tests.
Suggested change
|
||||
|
|
||||
| trait Owner: NewTrait { | ||||
| #[type_const] | ||||
| const C<const N: u32>: u32; | ||||
| #[type_const] | ||||
| const K<const N: u32>: u32; | ||||
| } | ||||
|
|
||||
| trait NewTrait {} | ||||
|
|
||||
| impl NewTrait for () {} | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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` | ||||
| } | ||||
| 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`. |
There was a problem hiding this comment.
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
Cin the trait impl.