Skip to content
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

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

Open
matthiaskrgr opened this issue Dec 27, 2023 · 0 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

#![feature(generic_arg_infer)]

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

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` labels Dec 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 27, 2023
@fmease fmease added I-cycle Issue: A query cycle occurred while none was expected and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants