query cycle: cycle detected when caching mir of `foo::{constant#1}` for CTFE
Open
Nobody has claimed this yet.
A-diagnostics
I-cycle
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn foo<const N: usize, const K: usize>(_data: [u32; N]) -> [u8; { foo(N); 5 }] {
[0; K]
}
fn main() {
}
Current output
error: generic parameters may not be used in const operations
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:71
|
3 | ...> [u8; { foo(N); 5 }] {
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
error[E0391]: cycle detected when caching mir of `foo::{constant#1}` for CTFE
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
|
note: ...which requires elaborating drops for `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires borrow-checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires const checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires preparing `foo::{constant#1}` for borrow checking...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires unsafety-checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires building MIR for `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires match-checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires type-checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires evaluating type-level constant...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `foo::{constant#1}`...
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
= note: ...which again requires caching mir of `foo::{constant#1}` for CTFE, completing the cycle
note: cycle used when const-evaluating + checking `foo::{constant#1}`
--> F2BA3E4A1C6EA7961BA8BFE1032468BB5A186D391F3B27D22A1638859E663E15.rs:3:65
|
3 | ... -> [u8; { foo(N); 5 }] {
| ^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error: aborting due to 2 previous errors
Desired output
We should have a proper diagnostic here and not talk about CTFE or mir
Rationale and extra context
cc https://github.com/rust-lang/rust/issues/119321
Other cases
No response
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Rust reproducer in the issue and reading the referenced rustc-dev-guide query and CTFE material. Compare the behavior with issue #119321 and trace the diagnostic path that emits the MIR/CTFE cycle; done means this case produces a proper diagnostic without exposing the internal cycle details.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100