Skip to content

query cycle: cycle detected when caching mir of foo::{constant#1} for CTFE #119345

@matthiaskrgr

Description

@matthiaskrgr
Member

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 #119321

Other cases

No response

Anything else?

No response

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
F-generic_arg_inferUsing `_` as a const argument: #![feature(generic_arg_infer)]`
on Dec 27, 2023
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 27, 2023
added
I-cycleIssue: A query cycle occurred while none was expected
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 25, 2024
removed
F-generic_arg_inferUsing `_` as a const argument: #![feature(generic_arg_infer)]`
on Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsI-cycleIssue: A query cycle occurred while none was expectedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @matthiaskrgr@fmease@BoxyUwU@rustbot

        Issue actions

          query cycle: cycle detected when caching mir of `foo::{constant#1}` for CTFE · Issue #119345 · rust-lang/rust