Closed
Description
// check-pass
#![feature(const_generics)]
struct Foo<const N: [u8; {
struct Foo<const N: usize>;
impl<const N: usize> Foo<N> {
fn value() -> usize {
N
}
}
Foo::<17>::value()
}]>;
fn main() {}
causes an ICE with
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:2:12
|
2 | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
error[E0391]: cycle detected when computing type of `Foo::N`
--> src/main.rs:4:18
|
4 | struct Foo<const N: [u8; {
| ^
|
= note: ...which again requires computing type of `Foo::N`, completing the cycle
note: cycle used when computing type of `Foo`
--> src/main.rs:4:1
|
4 | struct Foo<const N: [u8; {
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0391]: cycle detected when computing type of `Foo`
--> src/main.rs:4:1
|
4 | struct Foo<const N: [u8; {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires computing type of `Foo::N`...
--> src/main.rs:4:18
|
4 | struct Foo<const N: [u8; {
| ^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
--> src/main.rs:4:26
|
4 | struct Foo<const N: [u8; {
| __________________________^
5 | | struct Foo<const N: usize>;
6 | |
7 | | impl<const N: usize> Foo<N> {
... |
13 | | Foo::<17>::value()
14 | | }]>;
| |_^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
--> src/main.rs:4:26
|
4 | struct Foo<const N: [u8; {
| __________________________^
5 | | struct Foo<const N: usize>;
6 | |
7 | | impl<const N: usize> Foo<N> {
... |
13 | | Foo::<17>::value()
14 | | }]>;
| |_^
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
--> src/main.rs:4:26
|
4 | struct Foo<const N: [u8; {
| __________________________^
5 | | struct Foo<const N: usize>;
6 | |
7 | | impl<const N: usize> Foo<N> {
... |
13 | | Foo::<17>::value()
14 | | }]>;
| |_^
note: ...which requires type-checking `Foo::{{constant}}#0`...
--> src/main.rs:4:26
|
4 | struct Foo<const N: [u8; {
| __________________________^
5 | | struct Foo<const N: usize>;
6 | |
7 | | impl<const N: usize> Foo<N> {
... |
13 | | Foo::<17>::value()
14 | | }]>;
| |_^
note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`...
--> src/main.rs:5:5
|
5 | struct Foo<const N: usize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing the variances for items in this crate...
= note: ...which again requires computing type of `Foo`, completing the cycle
note: cycle used when collecting item types in top-level module
--> src/main.rs:2:1
|
2 | / #![feature(const_generics)]
3 | |
4 | | struct Foo<const N: [u8; {
5 | | struct Foo<const N: usize>;
... |
15 | |
16 | | fn main() {}
| |____________^
error: internal compiler error: src/librustc_typeck/variance/constraints.rs:165:17: `build_constraints_for_item` unsupported for this item
--> src/main.rs:4:1
|
4 | / struct Foo<const N: [u8; {
5 | | struct Foo<const N: usize>;
6 | |
7 | | impl<const N: usize> Foo<N> {
... |
13 | | Foo::<17>::value()
14 | | }]>;
| |____^
thread 'rustc' panicked at 'Box<Any>', /rustc/8aa18cbdc5d4bc33bd61e2d9a4b643d87f5d21de/src/libstd/macros.rs:13:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.46.0-nightly (8aa18cbdc 2020-07-08) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: aborting due to 3 previous errors; 1 warning emitted
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ayushmishra2005 commentedon Jul 18, 2020
@lcnr I would like to fix it. Can you please guide me?
lcnr commentedon Jul 18, 2020
I am not completely sure what's going wrong here myself yet.
I will try to look into what we can do here soon. If you open a new topic on zulip we can discuss it there.
lcnr commentedon Jul 18, 2020
Not completely sure why this ICEs after the cycle error, will have to ask about this myself.
edit: cycle errors don't actually cause a fatal error in some cases and return an error value instead, so the above now makes sense to me
We can fix the ice for now by ignoring
ty::Error
hererust/src/librustc_typeck/variance/constraints.rs
Lines 164 to 169 in 7d31ffc
The cycle error itself seems like a quite difficult problem though x.x
I don't have the time to think too much about this, but the short overview is the following:
N
while we compute the type ofFoo
.Bar::<u32>::value()
somewhat eagerly (for whatever reason), not sure about that oneBar::<u32>::value()
requires the variance ofT
inBar<T>
.Bar<T>
computes the variance ofFoo<N>
at the same time.Foo
for this, which causes an ICEThis luckily is outside of
min_const_generics
as proposed in rust-lang/lang-team#37 😅Rollup merge of rust-lang#74991 - JulianKnodt:74199, r=lcnr
Auto merge of rust-lang#74994 - JohnTitor:rollup-eknaekv, r=JohnTitor
Alexendoo commentedon Aug 2, 2020
Fixed by #74991
lcnr commentedon Aug 2, 2020
This shouldn't error, will open a new issue for that