Skip to content

Confusing diagnostic when doing a recursive call in a const block in a const fn: "cycle detected when elaborating drops" #125713

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

Open
theemathas opened this issue May 29, 2024 · 0 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

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

@theemathas theemathas 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. labels May 29, 2024
@fmease fmease added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) D-confusing Diagnostics: Confusing error or lint that should be reworked. A-const-fn labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. 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