Repository: rust
Issue: query cycle: cycle detected when caching mir of `foo::{constant#1}` for CTFE
Labels: A-diagnostics,T-compiler,F-generic_arg_infer,I-cycle

### Code

```Rust
#![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

```Shell
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

```Shell
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_