rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.95k stars 12.24k forks source link

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

Open theemathas opened 1 month ago

theemathas commented 1 month ago
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 ```rust const fn foo() { foo::<&T>() } const X: () = foo::(); ``` 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() { | ^^^^^^^^^^^^^^^^^ 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::` --> src/lib.rs:2:5 | 2 | foo::<&T>() | ^^^^^^^^^^^ note: inside `X` --> src/lib.rs:5:15 | 5 | const X: () = foo::(); | ^^^^^^^^^^^^ 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 ```rust 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```
fmease commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

That would also solve #114192.

saethlin commented 1 month ago

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 commented 1 month ago

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