Skip to content

nested const-eval queries don't have a recursion limit or timeout, causing the compiler to freeze in an infinite loop #125718

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

Closed
theemathas opened this issue May 29, 2024 · 8 comments · Fixed by #135167
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

theemathas commented May 29, 2024

const fn foo<T>() {
    const { foo::<&T>() }
}

const X: () = foo::<i32>();

The above code causes the compiler to hang, apparently in an infinite loop. I expected it to report an error due to a recursion limit or a timeout.

Note that removing the const block causes the compiler to correctly report an error.

Code without the const block
const fn foo<T>() {
    foo::<&T>()
}

const X: () = foo::<i32>();

This code results in the following error:

   Compiling playground v0.0.1 (/playground)
warning: function cannot return without recursing
 --> src/lib.rs:1:1
  |
1 | const fn foo<T>() {
  | ^^^^^^^^^^^^^^^^^ cannot return without recursing
2 |     foo::<&T>()
  |     ----------- recursive call site
  |
  = help: a `loop` may express intention better if this is on purpose
  = note: `#[warn(unconditional_recursion)]` on by default

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^ reached the configured maximum number of stack frames
  |
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<&i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `foo::<i32>`
 --> src/lib.rs:2:5
  |
2 |     foo::<&T>()
  |     ^^^^^^^^^^^
note: inside `X`
 --> src/lib.rs:5:15
  |
5 | const X: () = foo::<i32>();
  |               ^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0080`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib) due to 1 previous error; 1 warning emitted

Changing the infinite recursion into an infinite loop correctly causes a timeout.

Code with an infinite loop instead of an infinite recursion
const fn foo() {
    const { loop {} }
}

const X: () = foo();

This code results in the following error:

   Compiling playground v0.0.1 (/playground)
warning: unreachable expression
 --> src/lib.rs:2:5
  |
2 |     const { loop {} }
  |     ^^^^^^^^-------^^
  |     |       |
  |     |       any code following this expression is unreachable
  |     unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default

error: constant evaluation is taking a long time
 --> src/lib.rs:2:13
  |
2 |     const { loop {} }
  |             ^^^^^^^
  |
  = note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
          If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
 --> src/lib.rs:2:5
  |
2 |     const { loop {} }
  |     ^^^^^^^^^^^^^^^^^
  = note: `#[deny(long_running_const_eval)]` on by default

note: erroneous constant encountered
 --> src/lib.rs:2:5
  |
2 |     const { loop {} }
  |     ^^^^^^^^^^^^^^^^^

warning: function `foo` is never used
 --> src/lib.rs:1:10
  |
1 | const fn foo() {
  |          ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: constant `X` is never used
 --> src/lib.rs:5:7
  |
5 | const X: () = foo();
  |       ^

warning: `playground` (lib) generated 3 warnings
error: could not compile `playground` (lib) due to 1 previous error; 3 warnings emitted

See also #125713

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (da159eb33 2024-05-28)
binary: rustc
commit-hash: da159eb331b27df528185c616b394bb0e1d2a4bd
commit-date: 2024-05-28
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6```
@theemathas theemathas added the C-bug Category: This is a bug. label May 29, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 29, 2024
@theemathas theemathas changed the title const blocks don't have a recursion limit, causing the compiler to freeze in an infinite loop const blocks don't have a recursion limit or timeout, causing the compiler to freeze in an infinite loop May 29, 2024
@fmease fmease added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-fn and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 29, 2024
@fmease
Copy link
Member

fmease commented May 29, 2024

NB: This only affects polymorphically recursive calls (i.e., calls where the generic args change at each step). Normal recursive calls lead to cycle errors.

@oli-obk
Copy link
Contributor

oli-obk commented May 29, 2024

Hmm... The immediate solution I can come up with is to use the recursion limit to limit query depth, but that's going to be hard to tune to a good value without breaking random crates (most likely binary crates that we don't see on crater).

@fmease
Copy link
Member

fmease commented May 29, 2024

The immediate solution I can come up with is to use the recursion limit to limit query depth

That would also solve #114192.

@saethlin
Copy link
Member

I think there might be something else going on here. If I try to compile this reproducer I get a freeze with growing memory usage, which is what I would expect.

But if I try to ctrl-c the process, I... get a segfault?

╭ ➜ ben@archlinux:/tmp
╰ ➤ rustc +nightly ice.rs --crate-type=lib
^Cerror: rustc interrupted by SIGSEGV, printing backtrace

/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x3150996)[0x7de413b50996]
/usr/lib/libc.so.6(+0x3cae0)[0x7de410850ae0]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-45288dcc88911a1f.so(_ZN4core3fmt5write17hd4702675b19bc4d7E+0x8)[0x7de417308518]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c169)[0x7de41615c169]

### cycle encountered after 4 frames with period 6
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575b40d)[0x7de41615b40d]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c19b)[0x7de41615c19b]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575b40d)[0x7de41615b40d]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c19b)[0x7de41615c19b]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575b40d)[0x7de41615b40d]
/home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-4f8cb1b2fa29bc89.so(+0x575c19b)[0x7de41615c19b]
### recursed 42 times


note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
Segmentation fault (core dumped)

@oli-obk
Copy link
Contributor

oli-obk commented May 30, 2024

It probably tries to run the Ctrl-C handler and emit a mir interpreter backtrace, but that logic doesn't use ensure_sufficient_stack and hits the stack overflow protection. Queries on the other band just allocate more stack when necessary

@theemathas
Copy link
Contributor Author

The original code now segfaults on playground's nightly (2024-07-12 c6727fc). However, I am unable to reproduce the segfault on my computer.

@rustbot label +I-crash +regression-untriaged

   Compiling playground v0.0.1 (/playground)
error: rustc interrupted by SIGSEGV, printing backtrace

/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(+0x342a873)[0x7fb5d823d873]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14420)[0x7fb5d4cc1420]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(_RNvXNvNtNtCsf1a5ts8v4Q3_12rustc_middle2ty8instance11type_lengthNtB2_7VisitorINtNtCs4rQBiCPslym_13rustc_type_ir5visit11TypeVisitorNtNtB6_7context6TyCtxtE8visit_ty+0x9)[0x7fb5d9816ae3]

### cycle encountered after 3 frames with period 4
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(_RNvXNvNtNtCsf1a5ts8v4Q3_12rustc_middle2ty8instance11type_lengthNtB2_7VisitorINtNtCs4rQBiCPslym_13rustc_type_ir5visit11TypeVisitorNtNtB6_7context6TyCtxtE8visit_ty+0xb1)[0x7fb5d9816b8b]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(_RNvXNvNtNtCsf1a5ts8v4Q3_12rustc_middle2ty8instance11type_lengthNtB2_7VisitorINtNtCs4rQBiCPslym_13rustc_type_ir5visit11TypeVisitorNtNtB6_7context6TyCtxtE8visit_ty+0xb1)[0x7fb5d9816b8b]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(_RNvXNvNtNtCsf1a5ts8v4Q3_12rustc_middle2ty8instance11type_lengthNtB2_7VisitorINtNtCs4rQBiCPslym_13rustc_type_ir5visit11TypeVisitorNtNtB6_7context6TyCtxtE8visit_ty+0xb1)[0x7fb5d9816b8b]
/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(_RNvXNvNtNtCsf1a5ts8v4Q3_12rustc_middle2ty8instance11type_lengthNtB2_7VisitorINtNtCs4rQBiCPslym_13rustc_type_ir5visit11TypeVisitorNtNtB6_7context6TyCtxtE8visit_ty+0xb1)[0x7fb5d9816b8b]
### recursed 63 times

/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-7b97f2406392707f.so(_RNvXNvNtNtCsf1a5ts8v4Q3_12rustc_middle2ty8instance11type_lengthNtB2_7VisitorINtNtCs4rQBiCPslym_13rustc_type_ir5visit11TypeVisitorNtNtB6_7context6TyCtxtE8visit_ty+0xb1)[0x7fb5d9816b8b]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
error: could not compile `playground` (lib)

@rustbot rustbot added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. regression-untriaged Untriaged performance or correctness regression. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 31, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

The infinite loop started in 1.78. Before, it just emits a error:

error[E0658]: inline-const is experimental
 --> main.rs:2:5
  |
2 |     const { foo::<&T>() }
  |     ^^^^^
  |
  = note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information

@rustbot label -I-prioritize +P-medium -regression-untriaged +regression-from-stable-to-stable

@rustbot rustbot added P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. labels Oct 15, 2024
@RalfJung RalfJung changed the title const blocks don't have a recursion limit or timeout, causing the compiler to freeze in an infinite loop nested const-eval queries don't have a recursion limit or timeout, causing the compiler to freeze in an infinite loop Dec 1, 2024
@RalfJung
Copy link
Member

RalfJung commented Dec 1, 2024

The infinite loop started in 1.78. Before, it just emits a error:

That is the release that stabilized const blocks. I assume the infinite loop also happened before if you enable the nightly feature. So it's not really a regression, const blocks always behaved like this.

@RalfJung RalfJung removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. A-const-fn labels Dec 1, 2024
mzacho added a commit to mzacho/rust that referenced this issue Jan 6, 2025
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2025
… r=<try>

Depth limit const eval query

Currently the const-eval query doesn't have a recursion limit or timeout, causing the complier to freeze in an infinite loop, see rust-lang#125718. This PR depth limits the `eval_to_const_value_raw` query (with the [`recursion_limit`](https://doc.rust-lang.org/reference/attributes/limits.html) attribute) and improves the diagnostics for query overflow errors, so spans are reported for other dep kinds than `layout_of` (e.g. `eval_to_const_value_raw`).

fixes rust-lang#125718
fixes rust-lang#114192
@bors bors closed this as completed in 3ff1b64 Jan 13, 2025
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, ...) C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants