Confusing diagnostic when doing a recursive call in a const block in a const fn: "cycle detected when elaborating drops"
Open
Nobody has claimed this yet.
A-const-eval
A-diagnostics
D-confusing
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
const fn foo() {
const { foo() };
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when elaborating drops for `foo`
--> src/lib.rs:2:5
|
2 | const { foo() };
| ^^^^^^^^^^^^^^^
|
note: ...which requires simplifying constant for the type system `foo::{constant#0}`...
--> src/lib.rs:2:5
|
2 | const { foo() };
| ^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `foo::{constant#0}`...
--> src/lib.rs:2:5
|
2 | const { foo() };
| ^^^^^^^^^^^^^^^
note: ...which requires caching mir of `foo` for CTFE...
--> src/lib.rs:1:1
|
1 | const fn foo() {
| ^^^^^^^^^^^^^^
= note: ...which again requires elaborating drops for `foo`, completing the cycle
= note: cycle used when running analysis passes on this crate
= 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
For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
Something about constant evaluation failing.
Rationale and extra context
No response
Other cases
No response
Rust Version
Nightly rustc on the playground
1.80.0-nightly (2024-05-28 da159eb331b27df52818)
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 compiling the provided recursive const-block example with the referenced nightly Rust version and inspect how the diagnostic is produced. Trace the relevant compiler diagnostic path for the cycle and make the result describe constant-evaluation failure rather than an opaque drop-elaboration cycle; add or update a regression test if the relevant test location is found.
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